contrib/lz4/ossfuzz/decompress_frame_fuzzer.c in extlz4-0.3.1 vs contrib/lz4/ossfuzz/decompress_frame_fuzzer.c in extlz4-0.3.2
- old
+ new
@@ -7,10 +7,11 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "fuzz_helpers.h"
+#include "fuzz_data_producer.h"
#include "lz4.h"
#define LZ4F_STATIC_LINKING_ONLY
#include "lz4frame.h"
#include "lz4_helpers.h"
@@ -27,15 +28,21 @@
dict, dictSize, opts);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
+ FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
+ size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
+ size_t const dictSizeSeed = FUZZ_dataProducer_retrieve32(producer);
+ size = FUZZ_dataProducer_remainingBytes(producer);
- uint32_t seed = FUZZ_seed(&data, &size);
- size_t const dstCapacity = FUZZ_rand32(&seed, 0, 4 * size);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(
+ dstCapacitySeed, 0, 4 * size);
size_t const largeDictSize = 64 * 1024;
- size_t const dictSize = FUZZ_rand32(&seed, 0, largeDictSize);
+ size_t const dictSize = FUZZ_getRange_from_uint32(
+ dictSizeSeed, 0, largeDictSize);
+
char* const dst = (char*)malloc(dstCapacity);
char* const dict = (char*)malloc(dictSize);
LZ4F_decompressOptions_t opts;
LZ4F_dctx* dctx;
LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
@@ -60,8 +67,9 @@
decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
LZ4F_freeDecompressionContext(dctx);
free(dst);
free(dict);
+ FUZZ_dataProducer_free(producer);
return 0;
}