]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
reinforced fix for huge files
authorYann Collet <cyan@fb.com>
Thu, 25 Aug 2016 20:24:59 +0000 (22:24 +0200)
committerYann Collet <cyan@fb.com>
Thu, 25 Aug 2016 20:24:59 +0000 (22:24 +0200)
lib/compress/zstd_compress.c

index 0a2fb9afae4bf19247fe5e0efe045627a29f40dd..64bb7d4036951a857192d000697c4a9490c2d0a8 100644 (file)
@@ -2248,6 +2248,7 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, void* dst, size_t dstCa
 *   Frame is supposed already started (header already produced)
 *   @return : compressed size, or an error code
 */
+#include <stdio.h>
 static size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
                                      void* dst, size_t dstCapacity,
                                const void* src, size_t srcSize,
@@ -2274,8 +2275,10 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
         if (cctx->lowLimit > (1<<30)) {
             U32 const btplus = (cctx->params.cParams.strategy == ZSTD_btlazy2) | (cctx->params.cParams.strategy == ZSTD_btopt);
             U32 const chainMask = (1 << (cctx->params.cParams.chainLog - btplus)) - 1;
-            U32 const newLowLimit = (cctx->lowLimit & chainMask) + (chainMask+1);   /* preserve position % chainSize, ensure current-repcode doesn't underflow */
+            U32 const supLog = MAX(cctx->params.cParams.chainLog, 17 /* blockSize */);
+            U32 const newLowLimit = (cctx->lowLimit & chainMask) + (1 << supLog);   /* preserve position % chainSize, ensure current-repcode doesn't underflow */
             U32 const correction = cctx->lowLimit - newLowLimit;
+            fprintf(stderr, "chainMask : %u \n", chainMask);
             ZSTD_reduceIndex(cctx, correction);
             cctx->base += correction;
             cctx->dictBase += correction;