From: Yann Collet Date: Sun, 11 Dec 2016 23:25:07 +0000 (+0100) Subject: minor variation of rescale fix X-Git-Tag: v1.1.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c261f71f6a85dfcf66f612357782bd29acbb44c1;p=thirdparty%2Fzstd.git minor variation of rescale fix --- diff --git a/NEWS b/NEWS index 7f30f2d52..dc6c93234 100644 --- a/NEWS +++ b/NEWS @@ -1,14 +1,15 @@ v1.1.2 -Improved : faster decompression speed at ultra compression settings and in 32-bits mode +Improved : faster decompression speed at ultra compression settings and 32-bits mode cli : new : gzstd, experimental version able to decode .gz files, by Przemyslaw Skibinski cli : new : preserve file attributes cli : new : added zstdless and zstdgrep tools cli : fixed : status displays total amount decoded, even for file consisting of multiple frames (like pzstd) cli : fixed : zstdcat +lib : fixed : bug in streaming compression, by Nick Terrell lib : changed : only public ZSTD_ symbols are now exposed -API : changed : zbuff prototypes now generate deprecation warnings -API : changed : streaming decompression implicit reset on starting new frame -API : added experimental : dictID retrieval functions +API : zbuff : changed : prototypes now generate deprecation warnings +API : streaming : decompression : changed : implicit reset on starting new frames without init +API : experimental : added : dictID retrieval functions zlib_wrapper : added support for gz* functions, by Przemyslaw Skibinski Changed : zbuff source files moved to lib/deprecated Changed : reduced stack memory use diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index aef769fc0..35201a3a2 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -33,6 +33,7 @@ typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZS /*-************************************* * Helper functions ***************************************/ +#define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; } size_t ZSTD_compressBound(size_t srcSize) { return FSE_compressBound(srcSize) + 12; } @@ -2274,16 +2275,17 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, if (remaining < blockSize) blockSize = remaining; /* preemptive overflow correction */ - if (cctx->lowLimit > (1<<30)) { + if (cctx->lowLimit > (2U<<30)) { U32 const btplus = (cctx->params.cParams.strategy == ZSTD_btlazy2) | (cctx->params.cParams.strategy == ZSTD_btopt) | (cctx->params.cParams.strategy == ZSTD_btopt2); U32 const chainMask = (1 << (cctx->params.cParams.chainLog - btplus)) - 1; - U32 const supLog = MAX(cctx->params.cParams.windowLog, 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; + U32 const current = (U32)(ip - cctx->base); + U32 const newCurrent = (current & chainMask) + (1 << cctx->params.cParams.windowLog); + U32 const correction = current - newCurrent; + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_64 <= 30); ZSTD_reduceIndex(cctx, correction); cctx->base += correction; cctx->dictBase += correction; - cctx->lowLimit = newLowLimit; + cctx->lowLimit -= correction; cctx->dictLimit -= correction; if (cctx->nextToUpdate < correction) cctx->nextToUpdate = 0; else cctx->nextToUpdate -= correction; diff --git a/tests/longmatch.c b/tests/longmatch.c index c75c0d18e..61b81b359 100644 --- a/tests/longmatch.c +++ b/tests/longmatch.c @@ -1,10 +1,10 @@ -#define ZSTD_STATIC_LINKING_ONLY -#include "zstd.h" -#include "mem.h" #include #include #include #include +#include "mem.h" +#define ZSTD_STATIC_LINKING_ONLY +#include "zstd.h" int compress(ZSTD_CStream *ctx, ZSTD_outBuffer out, const void *data, size_t size) { ZSTD_inBuffer in = { data, size, 0 }; @@ -57,6 +57,8 @@ int main(int argc, const char** argv) { const char match[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const size_t randomData = (1 << windowLog) - 2*sizeof(match); size_t i; + printf("\n === Long Match Test === \n"); + printf("Creating random data to produce long matches \n"); for (i = 0; i < sizeof(match); ++i) { srcBuffer[i] = match[i]; } @@ -66,6 +68,7 @@ int main(int argc, const char** argv) { for (i = 0; i < sizeof(match); ++i) { srcBuffer[sizeof(match) + randomData + i] = match[i]; } + printf("Compressing, trying to generate a segfault \n"); if (compress(ctx, out, srcBuffer, size)) { return 1; } @@ -79,6 +82,7 @@ int main(int argc, const char** argv) { pos += block; compressed += block; } + printf("Compression completed successfully (no error triggered)\n"); free(srcBuffer); free(dstBuffer); }