]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor variation of rescale fix
authorYann Collet <cyan@fb.com>
Sun, 11 Dec 2016 23:25:07 +0000 (00:25 +0100)
committerYann Collet <cyan@fb.com>
Sun, 11 Dec 2016 23:25:07 +0000 (00:25 +0100)
NEWS
lib/compress/zstd_compress.c
tests/longmatch.c

diff --git a/NEWS b/NEWS
index 7f30f2d52008fb70eb7bd3be7c45538fcfc45fa5..dc6c93234d73d804d26552e2fd81475bbce762a8 100644 (file)
--- 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
index aef769fc0f4b0dabca965875577c85635a12c7a8..35201a3a2669843c5ca76a39fa3ad03a502c833d 100644 (file)
@@ -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;
index c75c0d18ef9bf2714ac3839db6afccfca82ecaca..61b81b359a403a527d316bccb6d81cdbcb984ee4 100644 (file)
@@ -1,10 +1,10 @@
-#define ZSTD_STATIC_LINKING_ONLY
-#include "zstd.h"
-#include "mem.h"
 #include <stdio.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
+#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);
   }