From a80f55f47d7d4076c19a000459b88e28e8c95eee Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 19 Dec 2024 07:38:14 -0800 Subject: [PATCH] added a test for ZSTD_compressSequencesAndLiterals checks that srcSize is present in the frame header and bounds the window size. --- tests/fuzzer.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 4901376ff..7907dbfad 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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");