Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
check that ZSTD_compressAndLiterals() also controls that the `srcSize` field is exact.
  • Loading branch information
Cyan4973 committed Dec 17, 2024
1 parent e501a11 commit 75b0132
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 75b0132

Please sign in to comment.