From 75b0132c57efb81516e52c6257395e6f94616057 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 16 Dec 2024 18:08:14 -0800 Subject: [PATCH] added tests check that ZSTD_compressAndLiterals() also controls that the `srcSize` field is exact. --- tests/fuzzer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 4901376ff..b20031708 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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)) { -- 2.47.2