]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix invalid use of dictionary offcode table
authorNick Terrell <terrelln@fb.com>
Fri, 13 Oct 2017 19:47:00 +0000 (12:47 -0700)
committerNick Terrell <terrelln@fb.com>
Fri, 13 Oct 2017 19:47:03 +0000 (12:47 -0700)
Fixes #888.

lib/compress/zstd_compress.c

index e072fe30e84355999c57529ab20c168b14f521ad..3f1a7cdbae405f22541f2cdec4eaf760934bf1a5 100644 (file)
@@ -1536,6 +1536,12 @@ MEM_STATIC size_t ZSTD_compressSequences(seqStore_t* seqStorePtr,
     int const uncompressibleError = (cSize == ERROR(dstSize_tooSmall)) && (srcSize <= dstCapacity);
     if (ZSTD_isError(cSize) && !uncompressibleError)
         return cSize;
+    /* We check that dictionaries have offset codes available for the first
+     * block. After the first block, the offcode table might not have large
+     * enough codes to represent the offsets in the data.
+     */
+    if (entropy->offcode_repeatMode == FSE_repeat_valid)
+        entropy->offcode_repeatMode = FSE_repeat_check;
 
     /* Check compressibility */
     {   size_t const minGain = ZSTD_minGain(srcSize);  /* note : fixed formula, maybe should depend on compression level, or strategy */