]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add a bound for matchlength dependent on window size
authorsenhuang42 <senhuang96@fb.com>
Tue, 17 Nov 2020 14:57:10 +0000 (09:57 -0500)
committersenhuang42 <senhuang96@fb.com>
Fri, 20 Nov 2020 21:58:25 +0000 (16:58 -0500)
tests/fuzz/Makefile
tests/fuzz/sequence_compression_api.c

index b309fa9d9e2d89934d0a61118366f2713d57e33a..36232a8cf5a54b7fdf03fc50aa40b9c2d8701086 100644 (file)
@@ -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 \
index b44bf147a177578923fbe063e99d77d44c1dbf29..97667ef5c948ccfc69b3e03cf150516777414e89 100644 (file)
@@ -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;