]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Modification to offset validation to include entire sequence
authorsenhuang42 <senhuang96@fb.com>
Tue, 17 Nov 2020 15:13:22 +0000 (10:13 -0500)
committersenhuang42 <senhuang96@fb.com>
Tue, 17 Nov 2020 15:13:22 +0000 (10:13 -0500)
lib/compress/zstd_compress.c
tests/fuzz/sequence_compression_api [new file with mode: 0755]

index 069835b23999e28e709ebd05c22f3f8a2dcc8e37..fbd4a80fa7cd2b18a91b212f75633f10495790aa 100644 (file)
@@ -4561,11 +4561,10 @@ static size_t ZSTD_copySequencesToSeqStoreBlockDelim(seqStore_t* seqStore, ZSTD_
         updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
 
         DEBUGLOG(6, "Storing sequence: (of: %u, ml: %u, ll: %u)", offCode, matchLength, litLength);
-        seqPos->posInSrc += litLength;
+        seqPos->posInSrc += litLength + matchLength;
         FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc,
                                                cctx->appliedParams.cParams.windowLog, dictSize),
                          "Sequence validation failed");
-        seqPos->posInSrc += matchLength;
         ZSTD_storeSeq(seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH);
         ip += matchLength + litLength;
     }
@@ -4682,11 +4681,10 @@ static size_t ZSTD_copySequencesToSeqStore(seqStore_t* seqStore, ZSTD_sequencePo
             updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
         }
 
-        seqPos->posInSrc += litLength;
+        seqPos->posInSrc += litLength + matchLength;
         FORWARD_IF_ERROR(ZSTD_validateSequence(offCode, matchLength, seqPos->posInSrc,
                                                cctx->appliedParams.cParams.windowLog, dictSize),
                          "Sequence validation failed");
-        seqPos->posInSrc += matchLength;
         DEBUGLOG(6, "Storing sequence: (of: %u, ml: %u, ll: %u)", offCode, matchLength, litLength);
         ZSTD_storeSeq(seqStore, litLength, ip, iend, offCode, matchLength - MINMATCH);
         ip += matchLength + litLength;
diff --git a/tests/fuzz/sequence_compression_api b/tests/fuzz/sequence_compression_api
new file mode 100755 (executable)
index 0000000..7ff7f55
Binary files /dev/null and b/tests/fuzz/sequence_compression_api differ