Add a bound for matchlength dependent on window size
diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile
index b309fa9..36232a8 100644
--- a/tests/fuzz/Makefile
+++ b/tests/fuzz/Makefile
@@ -28,7 +28,7 @@
 
 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 b44bf14..97667ef 100644
--- a/tests/fuzz/sequence_compression_api.c
+++ b/tests/fuzz/sequence_compression_api.c
@@ -134,6 +134,7 @@
     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 @@
     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 @@
         }
         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;