Exercise ZSTD_findDecompressedSize() in the simple decompression fuzzer (#3959)
* Improve decompression fuzzer * Fix legacy frame header fuzzer crash, add unit test
This commit is contained in:
@@ -37,7 +37,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
||||
size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, 10 * size);
|
||||
void *rBuf = FUZZ_malloc(bufSize);
|
||||
|
||||
ZSTD_decompressDCtx(dctx, rBuf, bufSize, src, size);
|
||||
size_t const dSize = ZSTD_decompressDCtx(dctx, rBuf, bufSize, src, size);
|
||||
if (!ZSTD_isError(dSize)) {
|
||||
/* If decompression was successful, the content size from the frame header(s) should be valid. */
|
||||
size_t const expectedSize = ZSTD_findDecompressedSize(src, size);
|
||||
FUZZ_ASSERT(expectedSize != ZSTD_CONTENTSIZE_ERROR);
|
||||
FUZZ_ASSERT(expectedSize == ZSTD_CONTENTSIZE_UNKNOWN || expectedSize == dSize);
|
||||
}
|
||||
free(rBuf);
|
||||
|
||||
FUZZ_dataProducer_free(producer);
|
||||
|
||||
Reference in New Issue
Block a user