File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,9 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
273
273
enc .Encode (& block , b )
274
274
addValues (& remain , block .literals )
275
275
litTotal += len (block .literals )
276
+ if len (block .sequences ) == 0 {
277
+ continue
278
+ }
276
279
seqs += len (block .sequences )
277
280
block .genCodes ()
278
281
addHist (& ll , block .coders .llEnc .Histogram ())
@@ -286,6 +289,9 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
286
289
if offset == 0 {
287
290
continue
288
291
}
292
+ if int (offset ) >= len (o .History ) {
293
+ continue
294
+ }
289
295
if offset > 3 {
290
296
newOffsets [offset - 3 ]++
291
297
} else {
@@ -336,6 +342,9 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
336
342
if seqs / nUsed < 512 {
337
343
// Use 512 as minimum.
338
344
nUsed = seqs / 512
345
+ if nUsed == 0 {
346
+ nUsed = 1
347
+ }
339
348
}
340
349
copyHist := func (dst * fseEncoder , src * [256 ]int ) ([]byte , error ) {
341
350
hist := dst .Histogram ()
@@ -358,6 +367,28 @@ func BuildDict(o BuildDictOptions) ([]byte, error) {
358
367
fakeLength += v
359
368
hist [i ] = uint32 (v )
360
369
}
370
+
371
+ // Ensure we aren't trying to represent RLE.
372
+ if maxCount == fakeLength {
373
+ for i := range hist {
374
+ if uint8 (i ) == maxSym {
375
+ fakeLength ++
376
+ maxSym ++
377
+ hist [i + 1 ] = 1
378
+ if maxSym > 1 {
379
+ break
380
+ }
381
+ }
382
+ if hist [0 ] == 0 {
383
+ fakeLength ++
384
+ hist [i ] = 1
385
+ if maxSym > 1 {
386
+ break
387
+ }
388
+ }
389
+ }
390
+ }
391
+
361
392
dst .HistogramFinished (maxSym , maxCount )
362
393
dst .reUsed = false
363
394
dst .useRLE = false
You can’t perform that action at this time.
0 commit comments