]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added tests
authorYann Collet <cyan@fb.com>
Tue, 17 Dec 2024 02:08:14 +0000 (18:08 -0800)
committerYann Collet <cyan@fb.com>
Fri, 20 Dec 2024 18:37:00 +0000 (10:37 -0800)
check that ZSTD_compressAndLiterals() also controls that the `srcSize` field is exact.

tests/fuzzer.c

index 4901376ffa2e1255969baa8e9cba7ee0089ce00a..b200317084e7db336196f10035fd67a078737f53 100644 (file)
@@ -3922,6 +3922,20 @@ static int basicUnitTests(U32 const seed, double compressibility)
                 goto _output_error;
             }
 
+            /* too short srcSize: must fail */
+            compressedSize = ZSTD_compressSequencesAndLiterals(cctx, dst, dstCapacity, seqs, nbSeqs, src, litSize, srcSize-1);
+            if (!ZSTD_isError(compressedSize)) {
+                DISPLAY("ZSTD_compressSequencesAndLiterals() should have failed: srcSize is too short\n");
+                goto _output_error;
+            }
+
+            /* too large srcSize: must fail */
+            compressedSize = ZSTD_compressSequencesAndLiterals(cctx, dst, dstCapacity, seqs, nbSeqs, src, litSize, srcSize+1);
+            if (!ZSTD_isError(compressedSize)) {
+                DISPLAY("ZSTD_compressSequencesAndLiterals() should have failed: srcSize is too short\n");
+                goto _output_error;
+            }
+
             /* correct amount of literals: should compress successfully */
             compressedSize = ZSTD_compressSequencesAndLiterals(cctx, dst, dstCapacity, seqs, nbSeqs, litBuffer, litSize, srcSize);
             if (ZSTD_isError(compressedSize)) {