diff options
author | Bimba Shrestha <bshrestha.msae@gmail.com> | 2019-08-30 17:27:42 (GMT) |
---|---|---|
committer | Bimba Shrestha <bshrestha.msae@gmail.com> | 2019-08-30 17:27:42 (GMT) |
commit | 7d153a704d00a266c9601c947e07fd33e1cd6f4d (patch) | |
tree | ab51d65880c31a8040251f378d1ef25ba6dd721e /ossfuzz/round_trip_fuzzer.c | |
parent | dc17d39c2fb962b591c73cf1467d89cf53b89156 (diff) | |
download | lz4-7d153a704d00a266c9601c947e07fd33e1cd6f4d.zip lz4-7d153a704d00a266c9601c947e07fd33e1cd6f4d.tar.gz lz4-7d153a704d00a266c9601c947e07fd33e1cd6f4d.tar.bz2 |
Making fuzzers use dataProducer api instead of random seed for decisions
Diffstat (limited to 'ossfuzz/round_trip_fuzzer.c')
-rw-r--r-- | ossfuzz/round_trip_fuzzer.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ossfuzz/round_trip_fuzzer.c b/ossfuzz/round_trip_fuzzer.c index 3a66e80..e37a0a6 100644 --- a/ossfuzz/round_trip_fuzzer.c +++ b/ossfuzz/round_trip_fuzzer.c @@ -10,10 +10,12 @@ #include "fuzz_helpers.h" #include "lz4.h" +#include "fuzz_data_producer.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - uint32_t seed = FUZZ_seed(&data, &size); + FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size); + size_t const partialCapacity = FUZZ_dataProducer_uint32(producer, 0, size); size_t const dstCapacity = LZ4_compressBound(size); char* const dst = (char*)malloc(dstCapacity); char* const rt = (char*)malloc(size); @@ -21,6 +23,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) FUZZ_ASSERT(dst); FUZZ_ASSERT(rt); + /* Restrict to remaining data from producer */ + size = FUZZ_dataProducer_remainingBytes(producer); + /* Compression must succeed and round trip correctly. */ int const dstSize = LZ4_compress_default((const char*)data, dst, size, dstCapacity); @@ -32,7 +37,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Partial decompression must succeed. */ { - size_t const partialCapacity = FUZZ_rand32(&seed, 0, size); char* const partial = (char*)malloc(partialCapacity); FUZZ_ASSERT(partial); int const partialSize = LZ4_decompress_safe_partial( @@ -43,8 +47,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) free(partial); } + free(dst); free(rt); + FUZZ_dataProducer_free(producer); return 0; } |