From: Yann Collet Date: Thu, 26 Jan 2017 00:39:03 +0000 (-0800) Subject: added test of new parameter ZSTD_p_forceWindow X-Git-Tag: v1.1.3^2~19^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06e7697f964e486b062b92e0656749dc54b73d47;p=thirdparty%2Fzstd.git added test of new parameter ZSTD_p_forceWindow --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 95c7e1a7a..b6cf37646 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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; diff --git a/lib/compress/zstdmt_compress.h b/lib/compress/zstdmt_compress.h index 1288c1ed0..4757e3e06 100644 --- a/lib/compress/zstdmt_compress.h +++ b/lib/compress/zstdmt_compress.h @@ -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. diff --git a/lib/zstd.h b/lib/zstd.h index 7a0aa3304..8325710b7 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -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() : diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 00cfb0574..60546c07a 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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