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:
Elliot Gorokhovsky authored and GitHub committed 2024-03-12 17:07:06 -04:00
1 parent 92fbd42894
commit f65b9e27ce
3 files changed
+25 -1

No files matched your search

+7 -1
View File
@@ -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);