]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added a test for ZSTD_compressSequencesAndLiterals
authorYann Collet <cyan@fb.com>
Thu, 19 Dec 2024 15:38:14 +0000 (07:38 -0800)
committerYann Collet <cyan@fb.com>
Fri, 20 Dec 2024 18:37:00 +0000 (10:37 -0800)
checks that srcSize is present in the frame header
and bounds the window size.

tests/fuzzer.c

index 4901376ffa2e1255969baa8e9cba7ee0089ce00a..7907dbfad86beea776f18974cfae2bd78989a6b0 100644 (file)
@@ -3880,7 +3880,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
 
     DISPLAYLEVEL(3, "test%3i : ZSTD_compressSequencesAndLiterals : ", testNb++);
     {
-        const size_t srcSize = 500 KB;
+        const size_t srcSize = 497000;
         const BYTE* const src = (BYTE*)CNBuffer;
         BYTE* const dst = (BYTE*)compressedBuffer;
         const size_t dstCapacity = ZSTD_compressBound(srcSize);
@@ -3929,6 +3929,21 @@ static int basicUnitTests(U32 const seed, double compressibility)
                 goto _output_error;
             }
         }
+        {   ZSTD_frameHeader zfh;
+            size_t const zfhStatus = ZSTD_getFrameHeader(&zfh, dst, compressedSize);
+            if (zfhStatus != 0) {
+                DISPLAY("Error reading frame header\n");
+                goto _output_error;
+            }
+            if (zfh.frameContentSize != srcSize) {
+                DISPLAY("Error: ZSTD_compressSequencesAndLiterals() did not report srcSize in the frame header\n");
+                goto _output_error;
+            }
+            if (zfh.windowSize > srcSize) {
+                DISPLAY("Error: ZSTD_compressSequencesAndLiterals() did not resized window size to smaller contentSize\n");
+                goto _output_error;
+            }
+        }
         {   size_t const dSize = ZSTD_decompress(decompressBuffer, decompressSize, dst, compressedSize);
             if (ZSTD_isError(dSize)) {
                 DISPLAY("Error during decompression of frame produced by ZSTD_compressSequencesAndLiterals()\n");