Combining fuzz_data_producer restrict calls into a single function
This commit is contained in:
parent
23cc2d8510
commit
b5b24c2a0d
@ -55,8 +55,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
int cLevel = FUZZ_dataProducer_uint32(producer) % kMaxClevel;
|
int cLevel = FUZZ_dataProducer_uint32(producer) % kMaxClevel;
|
||||||
|
|
||||||
|
@ -27,8 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
FUZZ_dict_t dict;
|
FUZZ_dict_t dict;
|
||||||
ZSTD_DDict* ddict = NULL;
|
ZSTD_DDict* ddict = NULL;
|
||||||
|
@ -71,8 +71,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
size_t const rBufSize = size;
|
size_t const rBufSize = size;
|
||||||
void* rBuf = malloc(rBufSize);
|
void* rBuf = malloc(rBufSize);
|
||||||
|
@ -65,3 +65,10 @@ size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize)
|
|||||||
producer->size = newSize;
|
producer->size = newSize;
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t FUZZ_dataProducer_reserveDataPrefix(FUZZ_dataProducer_t *producer)
|
||||||
|
{
|
||||||
|
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(
|
||||||
|
producer, 0, producer->size);
|
||||||
|
return FUZZ_dataProducer_contract(producer, producerSliceSize);
|
||||||
|
}
|
||||||
|
@ -44,10 +44,13 @@ uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer);
|
|||||||
/* Returns the size of the remaining bytes of data in the producer */
|
/* Returns the size of the remaining bytes of data in the producer */
|
||||||
size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer);
|
size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer);
|
||||||
|
|
||||||
/* Tells the producer to contract to newSize bytes of data it currently uses,
|
/* Restricts the producer to only the last newSize bytes of data.
|
||||||
counted from the end, and forget about the rest. If newSize > current data size,
|
If newSize > current data size, nothing happens. Returns the number of bytes
|
||||||
nothing happens. Returns the number of bytes the producer won't use anymore,
|
the producer won't use anymore, after contracting. */
|
||||||
after contracting. */
|
|
||||||
size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize);
|
size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize);
|
||||||
|
|
||||||
|
/* Restricts the producer to use only the last X bytes of data, where X is
|
||||||
|
a random number in the interval [0, data_size]. Returns the size of the
|
||||||
|
remaining data the producer won't use anymore (the prefix). */
|
||||||
|
size_t FUZZ_dataProducer_reserveDataPrefix(FUZZ_dataProducer_t *producer);
|
||||||
#endif // FUZZ_DATA_PRODUCER_H
|
#endif // FUZZ_DATA_PRODUCER_H
|
||||||
|
@ -27,8 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
size_t const maxSize = ZSTD_compressBound(size);
|
size_t const maxSize = ZSTD_compressBound(size);
|
||||||
size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, maxSize);
|
size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, maxSize);
|
||||||
|
@ -26,8 +26,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
if (!dctx) {
|
if (!dctx) {
|
||||||
dctx = ZSTD_createDCtx();
|
dctx = ZSTD_createDCtx();
|
||||||
|
@ -55,8 +55,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
/* Half of the time fuzz with a 1 byte smaller output size.
|
/* Half of the time fuzz with a 1 byte smaller output size.
|
||||||
* This will still succeed because we don't use a dictionary, so the dictID
|
* This will still succeed because we don't use a dictionary, so the dictID
|
||||||
|
@ -56,8 +56,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
/* Allocate all buffers and contexts if not already allocated */
|
/* Allocate all buffers and contexts if not already allocated */
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
|
@ -128,8 +128,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
|||||||
/* Give a random portion of src data to the producer, to use for
|
/* Give a random portion of src data to the producer, to use for
|
||||||
parameter generation. The rest will be used for (de)compression */
|
parameter generation. The rest will be used for (de)compression */
|
||||||
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
|
||||||
size_t producerSliceSize = FUZZ_dataProducer_uint32Range(producer, 0, size);
|
size = FUZZ_dataProducer_reserveDataPrefix(producer);
|
||||||
size = FUZZ_dataProducer_contract(producer, producerSliceSize);
|
|
||||||
|
|
||||||
size_t neededBufSize;
|
size_t neededBufSize;
|
||||||
neededBufSize = ZSTD_compressBound(size) * 5;
|
neededBufSize = ZSTD_compressBound(size) * 5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user