From f80dec66b0fdeeb0bb08ab4739a2549476e8cb4e Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Thu, 22 Apr 2021 18:21:43 -0400 Subject: [PATCH 1/2] Add DDS to oss fuzzer --- tests/fuzz/zstd_helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fuzz/zstd_helpers.c b/tests/fuzz/zstd_helpers.c index fcbe3361d99..31bf4c20dad 100644 --- a/tests/fuzz/zstd_helpers.c +++ b/tests/fuzz/zstd_helpers.c @@ -92,6 +92,7 @@ void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, FUZZ_dataProducer setRand(cctx, ZSTD_c_nbWorkers, 0, 2, producer); setRand(cctx, ZSTD_c_rsyncable, 0, 1, producer); setRand(cctx, ZSTD_c_useRowMatchFinder, 0, 2, producer); + setRand(cctx, ZSTD_c_enableDedicatedDictSearch, 0, 1, producer); setRand(cctx, ZSTD_c_forceMaxWindow, 0, 1, producer); setRand(cctx, ZSTD_c_literalCompressionMode, 0, 2, producer); setRand(cctx, ZSTD_c_forceAttachDict, 0, 2, producer); From efa6dfa7293722060edd09427760e4ad3837d88b Mon Sep 17 00:00:00 2001 From: felixhandte Date: Fri, 23 Apr 2021 16:34:21 -0400 Subject: [PATCH 2/2] Apply DDS adjustments to avoid assert failures --- lib/compress/zstd_compress.c | 11 +++++++---- lib/compress/zstd_lazy.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index a5cf106b4f0..d39e74b3c20 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -3365,7 +3365,7 @@ static U32 ZSTD_resolveRepcodeToRawOffset(const U32 rep[ZSTD_REP_NUM], const U32 * ZSTD_seqStore_resolveOffCodes() reconciles any possible divergences in offset history that may arise * due to emission of RLE/raw blocks that disturb the offset history, and replaces any repcodes within * the seqStore that may be invalid. - * + * * dRepcodes are updated as would be on the decompression side. cRepcodes are updated exactly in * accordance with the seqStore. */ @@ -3555,14 +3555,14 @@ static size_t ZSTD_compressBlock_splitBlock_internal(ZSTD_CCtx* zc, void* dst, s * may become invalid. In order to reconcile potentially invalid repcodes, we keep track of two * separate repcode histories that simulate repcode history on compression and decompression side, * and use the histories to determine whether we must replace a particular repcode with its raw offset. - * + * * 1) cRep gets updated for each partition, regardless of whether the block was emitted as uncompressed * or RLE. This allows us to retrieve the offset value that an invalid repcode references within * a nocompress/RLE block. * 2) dRep gets updated only for compressed partitions, and when a repcode gets replaced, will use * the replacement offset value rather than the original repcode to update the repcode history. * dRep also will be the final repcode history sent to the next block. - * + * * See ZSTD_seqStore_resolveOffCodes() for more details. */ repcodes_t dRep; @@ -6192,7 +6192,7 @@ static int ZSTD_dedicatedDictSearch_isSupported( { return (cParams->strategy >= ZSTD_greedy) && (cParams->strategy <= ZSTD_lazy2) - && (cParams->hashLog >= cParams->chainLog) + && (cParams->hashLog > cParams->chainLog) && (cParams->chainLog <= 24); } @@ -6211,6 +6211,9 @@ static void ZSTD_dedicatedDictSearch_revertCParams( case ZSTD_lazy: case ZSTD_lazy2: cParams->hashLog -= ZSTD_LAZY_DDSS_BUCKET_LOG; + if (cParams->hashLog < ZSTD_HASHLOG_MIN) { + cParams->hashLog = ZSTD_HASHLOG_MIN; + } break; case ZSTD_btlazy2: case ZSTD_btopt: diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index 26b2c2ad8e7..5d824beed9a 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -469,7 +469,7 @@ void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t* ms, const B U32 hashIdx; assert(ms->cParams.chainLog <= 24); - assert(ms->cParams.hashLog >= ms->cParams.chainLog); + assert(ms->cParams.hashLog > ms->cParams.chainLog); assert(idx != 0); assert(tmpMinChain <= minChain); @@ -500,7 +500,7 @@ void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t* ms, const B if (count == cacheSize) { for (count = 0; count < chainLimit;) { if (i < minChain) { - if (!i || countBeyondMinChain++ > cacheSize) { + if (!i || ++countBeyondMinChain > cacheSize) { /* only allow pulling `cacheSize` number of entries * into the cache or chainTable beyond `minChain`, * to replace the entries pulled out of the