From: senhuang42 Date: Tue, 17 Nov 2020 14:57:10 +0000 (-0500) Subject: Add a bound for matchlength dependent on window size X-Git-Tag: v1.4.7~29^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a73a07b189c1eef5a53c3f1588088b663197210e;p=thirdparty%2Fzstd.git Add a bound for matchlength dependent on window size --- diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile index b309fa9d9..36232a8cf 100644 --- a/tests/fuzz/Makefile +++ b/tests/fuzz/Makefile @@ -28,7 +28,7 @@ PRGDIR = ../../programs FUZZ_CPPFLAGS := -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \ -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(ZSTDDIR)/legacy \ - -I$(PRGDIR) -DZSTD_MULTITHREAD -DZSTD_LEGACY_SUPPORT=1 -DDEBUGLEVEL=5 $(CPPFLAGS) + -I$(PRGDIR) -DZSTD_MULTITHREAD -DZSTD_LEGACY_SUPPORT=1 $(CPPFLAGS) FUZZ_EXTRA_FLAGS := -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ -Wstrict-prototypes -Wundef \ diff --git a/tests/fuzz/sequence_compression_api.c b/tests/fuzz/sequence_compression_api.c index b44bf147a..97667ef5c 100644 --- a/tests/fuzz/sequence_compression_api.c +++ b/tests/fuzz/sequence_compression_api.c @@ -134,6 +134,7 @@ static size_t generateRandomSequences(FUZZ_dataProducer_t* producer, uint32_t nbSeqGenerated = 0; uint32_t litLength; uint32_t matchLength; + uint32_t matchBound; uint32_t offset; uint32_t offsetBound; uint32_t repCode = 0; @@ -143,6 +144,7 @@ static size_t generateRandomSequences(FUZZ_dataProducer_t* producer, while (nbSeqGenerated < ZSTD_FUZZ_MAX_NBSEQ && bytesGenerated < ZSTD_FUZZ_GENERATED_SRC_MAXSIZE && !FUZZ_dataProducer_empty(producer)) { + matchBound = ZSTD_FUZZ_MATCHLENGTH_MAXSIZE; litLength = isFirstSequence && dictSize == 0 ? FUZZ_dataProducer_uint32Range(producer, 1, literalsSizeLimit) : FUZZ_dataProducer_uint32Range(producer, 0, literalsSizeLimit); bytesGenerated += litLength; @@ -151,7 +153,16 @@ static size_t generateRandomSequences(FUZZ_dataProducer_t* producer, } offsetBound = bytesGenerated > windowSize ? windowSize : bytesGenerated + dictSize; offset = FUZZ_dataProducer_uint32Range(producer, 1, offsetBound); - matchLength = FUZZ_dataProducer_uint32Range(producer, ZSTD_MINMATCH_MIN, ZSTD_FUZZ_MATCHLENGTH_MAXSIZE); + if (dictSize > 0 && bytesGenerated <= windowSize) { + uint32_t bytesToReachWindowSize = windowSize - bytesGenerated; + if (bytesToReachWindowSize < ZSTD_MINMATCH_MIN) { + offset = FUZZ_dataProducer_uint32Range(producer, 1, windowSize); + } else { + matchBound = bytesToReachWindowSize > ZSTD_FUZZ_MATCHLENGTH_MAXSIZE ? + ZSTD_FUZZ_MATCHLENGTH_MAXSIZE : bytesToReachWindowSize; + } + } + matchLength = FUZZ_dataProducer_uint32Range(producer, ZSTD_MINMATCH_MIN, matchBound); bytesGenerated += matchLength; if (bytesGenerated > ZSTD_FUZZ_GENERATED_SRC_MAXSIZE) { break;