]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed : compression bug on very large files
authorYann Collet <cyan@fb.com>
Thu, 25 Aug 2016 12:34:42 +0000 (14:34 +0200)
committerYann Collet <cyan@fb.com>
Thu, 25 Aug 2016 12:34:42 +0000 (14:34 +0200)
lib/compress/zstd_compress.c

index e0ae91bf86c5b33c0a219e2cebf8520cb5795864..0a2fb9afae4bf19247fe5e0efe045627a29f40dd 100644 (file)
@@ -2274,7 +2274,7 @@ 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;   /* preserve position % chainSize */
+            U32 const newLowLimit = (cctx->lowLimit & chainMask) + (chainMask+1);   /* preserve position % chainSize, ensure current-repcode doesn't underflow */
             U32 const correction = cctx->lowLimit - newLowLimit;
             ZSTD_reduceIndex(cctx, correction);
             cctx->base += correction;