Add support for in-place decompression
* Add a function and macro ZSTD_decompressionMargin() that computes the decompression margin for in-place decompression. The function computes a tight margin that works in all cases, and the macro computes an upper bound that will only work if flush isn't used. * When doing in-place decompression, make sure that our output buffer doesn't overlap with the input buffer. This ensures that we don't decide to use the portion of the output buffer that overlaps the input buffer for temporary memory, like for literals. * Add a simple unit test. * Add in-place decompression to the simple_round_trip and stream_round_trip fuzzers. This should help verify that our margin stays correct.
This commit is contained in:
committed by
Nick Terrell
parent
423500d1ae
commit
5b266196a4
@@ -166,6 +166,24 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
||||
FUZZ_ZASSERT(rSize);
|
||||
FUZZ_ASSERT_MSG(rSize == size, "Incorrect regenerated size");
|
||||
FUZZ_ASSERT_MSG(!FUZZ_memcmp(src, rBuf, size), "Corruption!");
|
||||
|
||||
/* Test in-place decompression (note the macro doesn't work in this case) */
|
||||
{
|
||||
size_t const margin = ZSTD_decompressionMargin(cBuf, cSize);
|
||||
size_t const outputSize = size + margin;
|
||||
char* const output = (char*)FUZZ_malloc(outputSize);
|
||||
char* const input = output + outputSize - cSize;
|
||||
size_t dSize;
|
||||
FUZZ_ASSERT(outputSize >= cSize);
|
||||
memcpy(input, cBuf, cSize);
|
||||
|
||||
dSize = ZSTD_decompressDCtx(dctx, output, outputSize, input, cSize);
|
||||
FUZZ_ZASSERT(dSize);
|
||||
FUZZ_ASSERT_MSG(dSize == size, "Incorrect regenerated size");
|
||||
FUZZ_ASSERT_MSG(!FUZZ_memcmp(src, output, size), "Corruption!");
|
||||
|
||||
free(output);
|
||||
}
|
||||
}
|
||||
|
||||
FUZZ_dataProducer_free(producer);
|
||||
|
||||
Reference in New Issue
Block a user