]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added test of new parameter ZSTD_p_forceWindow
authorYann Collet <cyan@fb.com>
Thu, 26 Jan 2017 00:39:03 +0000 (16:39 -0800)
committerYann Collet <cyan@fb.com>
Thu, 26 Jan 2017 00:39:03 +0000 (16:39 -0800)
lib/compress/zstd_compress.c
lib/compress/zstdmt_compress.h
lib/zstd.h
tests/fuzzer.c

index 95c7e1a7a915251baa6a1844a1f550288081ca7d..b6cf37646bfc5d80523111f60b8232a9e7be049b 100644 (file)
@@ -123,7 +123,7 @@ size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned
 {
     switch(param)
     {
-    case ZSTD_p_forceWindow : cctx->forceWindow = value; return 0;
+    case ZSTD_p_forceWindow : cctx->forceWindow = value>0; cctx->loadedDictEnd = 0; return 0;
     default: return ERROR(parameter_unknown);
     }
 }
@@ -2323,7 +2323,7 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
             else cctx->nextToUpdate -= correction;
         }
 
-        if ((U32)(ip+blockSize - cctx->base) > (cctx->forceWindow ? 0 : cctx->loadedDictEnd) + maxDist) {
+        if ((U32)(ip+blockSize - cctx->base) > cctx->loadedDictEnd + maxDist) {
             /* enforce maxDist */
             U32 const newLowLimit = (U32)(ip+blockSize - cctx->base) - maxDist;
             if (cctx->lowLimit < newLowLimit) cctx->lowLimit = newLowLimit;
@@ -2477,7 +2477,7 @@ static size_t ZSTD_loadDictionaryContent(ZSTD_CCtx* zc, const void* src, size_t
     zc->dictBase = zc->base;
     zc->base += ip - zc->nextSrc;
     zc->nextToUpdate = zc->dictLimit;
-    zc->loadedDictEnd = (U32)(iend - zc->base);
+    zc->loadedDictEnd = zc->forceWindow ? 0 : (U32)(iend - zc->base);
 
     zc->nextSrc = iend;
     if (srcSize <= HASH_READ_SIZE) return 0;
index 1288c1ed0cc5cb904aa26f14400769cbeec5091b..4757e3e06d4d8432215d5c706984ae2723cee07b 100644 (file)
@@ -51,8 +51,9 @@ ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx, const void* d
 
 /* ZSDTMT_parameter :
  * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
-typedef enum { ZSTDMT_p_sectionSize    /* size of input "section". Each section is compressed in parallel. 0 means default, which is dynamically determined within compression functions */
-    } ZSDTMT_parameter;
+typedef enum {
+    ZSTDMT_p_sectionSize    /* size of input "section". Each section is compressed in parallel. 0 means default, which is dynamically determined within compression functions */
+} ZSDTMT_parameter;
 
 /* ZSTDMT_setMTCtxParameter() :
  * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
index 7a0aa3304336feec3119e2d340b42df519de8725..8325710b7d588ac488c33cc082029c2c7d437ba5 100644 (file)
@@ -404,7 +404,9 @@ ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
 /*! ZSTD_setCCtxParameter() :
  *  Set advanced parameters, selected through enum ZSTD_CCtxParameter
  *  @result : 0, or an error code (which can be tested with ZSTD_isError()) */
-typedef enum { ZSTD_p_forceWindow } ZSTD_CCtxParameter;
+typedef enum {
+    ZSTD_p_forceWindow   /* Force back-references to remain < windowSize, even when referencing Dictionary content (default:0)*/
+} ZSTD_CCtxParameter;
 size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned value);
 
 /*! ZSTD_createCDict_byReference() :
index 00cfb057463f1bf2efcdf24104b0bec4c1e7069e..60546c07a7d18912b1e2c6f27a2046c5000cbc92 100644 (file)
@@ -755,6 +755,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, U32 const maxD
                 CHECK (ZSTD_isError(errorCode), "ZSTD_copyCCtx error : %s", ZSTD_getErrorName(errorCode));
         }   }
         XXH64_reset(&xxhState, 0);
+        ZSTD_setCCtxParameter(ctx, ZSTD_p_forceWindow, FUZ_rand(&lseed) & 1);
         {   U32 const nbChunks = (FUZ_rand(&lseed) & 127) + 2;
             U32 n;
             for (totalTestSize=0, cSize=0, n=0 ; n<nbChunks ; n++) {