From 96bdd87de4e40ae3fa921afe98a42f0184cb89fe Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 25 Aug 2016 14:34:42 +0200 Subject: [PATCH] fixed : compression bug on very large files --- lib/compress/zstd_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index e0ae91bf..0a2fb9af 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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;