{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, LZ4_compressBound(size));
LZ4F_preferences_t const prefs = FUZZ_dataProducer_preferences(producer);
- size_t const compressBound = LZ4F_compressFrameBound(FUZZ_dataProducer_remainingBytes(producer), &prefs);
- size_t const dstCapacitySeed = FUZZ_dataProducer_uint32_seed(producer, 0, compressBound);
- size_t const dstCapacity = FUZZ_dataProducer_uint32(dstCapacitySeed,
- 0, FUZZ_dataProducer_remainingBytes(producer));
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const compressBound = LZ4F_compressFrameBound(size, &prefs);
+ size_t const dstCapacitySeed = FUZZ_dataProducer_uint32(producer, 0, compressBound);
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, size);
+
char* const dst = (char*)malloc(dstCapacity);
char* const rt = (char*)malloc(size);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
- /* Restrict to remaining data from producer */
- size = FUZZ_dataProducer_remainingBytes(producer);
-
/* If compression succeeds it must round trip correctly. */
size_t const dstSize =
LZ4F_compressFrame(dst, dstCapacity, data, size, &prefs);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- size_t const dstCapacitySeed = FUZZ_dataProducer_uint32_seed(producer, 0, LZ4_compressBound(size));
- size_t const dstCapacity = FUZZ_dataProducer_uint32(dstCapacitySeed,
- 0, LZ4_compressBound(FUZZ_dataProducer_remainingBytes(producer)));
- char* const dst = (char*)malloc(dstCapacity);
- char* const rt = (char*)malloc(size);
+ size_t const dstCapacitySeed = FUZZ_dataProducer_uint32(producer, 0, LZ4_compressBound(size));
- /* Restrict to remaining data from producer */
size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, LZ4_compressBound(size));
+
+ char* const dst = (char*)malloc(dstCapacity);
+ char* const rt = (char*)malloc(size);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- size_t const dstCapacitySeed = FUZZ_dataProducer_uint32_seed(producer,
+ size_t const dstCapacitySeed = FUZZ_dataProducer_uint32(producer,
0, LZ4_compressBound(size));
- size_t const levelSeed = FUZZ_dataProducer_uint32_seed(producer,
+ size_t const levelSeed = FUZZ_dataProducer_uint32(producer,
LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
- size_t const dstCapacity = FUZZ_dataProducer_uint32(dstCapacitySeed,
- 0, FUZZ_dataProducer_remainingBytes(producer));
- int const level = FUZZ_dataProducer_uint32(
- levelSeed, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
- char* const dst = (char*)malloc(dstCapacity);
- char* const rt = (char*)malloc(size);
- /* Restrict to remaining data from producer */
size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, size);
+ int const level = FUZZ_getRange_from_uint32(levelSeed, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
+
+ char* const dst = (char*)malloc(dstCapacity);
+ char* const rt = (char*)malloc(size);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- size_t const dstCapacitySeed = FUZZ_dataProducer_uint32_seed(producer,
+ size_t const dstCapacitySeed = FUZZ_dataProducer_uint32(producer,
0, 4 * size);
size_t const largeDictSize = 64 * 1024;
- size_t const dictSizeSeed = FUZZ_dataProducer_uint32_seed(producer,
+ size_t const dictSizeSeed = FUZZ_dataProducer_uint32(producer,
0, largeDictSize);
- size_t const dstCapacity = FUZZ_dataProducer_uint32(
- dstCapacitySeed, 0, 4 * FUZZ_dataProducer_remainingBytes(producer));
- size_t const dictSize = FUZZ_dataProducer_uint32(
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(
+ dstCapacitySeed, 0, 4 * size);
+ 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);
- /* Restrict to remaining data from producer */
- size = FUZZ_dataProducer_remainingBytes(producer);
-
FUZZ_ASSERT(dctx);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(dict);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- size_t const dstCapacitySeed = FUZZ_dataProducer_uint32_seed(producer, 0, 4 * size);
- size_t const dstCapacity = FUZZ_dataProducer_uint32(dstCapacitySeed,
- 0, 4 * FUZZ_dataProducer_remainingBytes(producer));
+ size_t const dstCapacitySeed = FUZZ_dataProducer_uint32(producer, 0, 4 * size);
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, 4 * size);
+
size_t const smallDictSize = size + 1;
size_t const largeDictSize = 64 * 1024 - 1;
size_t const dictSize = MAX(smallDictSize, largeDictSize);
char* const dataAfterDict = dict + dictSize;
char* const smallDict = dataAfterDict - smallDictSize;
- /* Restrict to remaining data from producer */
- size = FUZZ_dataProducer_remainingBytes(producer);
-
FUZZ_ASSERT(dst);
FUZZ_ASSERT(dict);
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer) { free(producer); }
-uint32_t FUZZ_dataProducer_uint32_seed(FUZZ_dataProducer_t *producer, uint32_t min,
+uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer, uint32_t min,
uint32_t max) {
FUZZ_ASSERT(min <= max);
return result;
}
-uint32_t FUZZ_dataProducer_uint32(uint32_t seed, uint32_t min, uint32_t max)
+uint32_t FUZZ_getRange_from_uint32(uint32_t seed, uint32_t min, uint32_t max)
{
uint32_t range = max - min;
if (range == 0xffffffff) {
return min + seed % (range + 1);
}
-uint32_t FUZZ_dataProducer_uint32NonAdaptive(FUZZ_dataProducer_t* producer,
+uint32_t FUZZ_dataProducer_range32(FUZZ_dataProducer_t* producer,
uint32_t min, uint32_t max)
{
- size_t const seed = FUZZ_dataProducer_uint32_seed(producer, min, max);
- return FUZZ_dataProducer_uint32(seed, min, max);
+ size_t const seed = FUZZ_dataProducer_uint32(producer, min, max);
+ return FUZZ_getRange_from_uint32(seed, min, max);
}
LZ4F_frameInfo_t FUZZ_dataProducer_frameInfo(FUZZ_dataProducer_t* producer)
{
LZ4F_frameInfo_t info = LZ4F_INIT_FRAMEINFO;
- info.blockSizeID = FUZZ_dataProducer_uint32NonAdaptive(producer, LZ4F_max64KB - 1, LZ4F_max4MB);
+ info.blockSizeID = FUZZ_dataProducer_range32(producer, LZ4F_max64KB - 1, LZ4F_max4MB);
if (info.blockSizeID < LZ4F_max64KB) {
info.blockSizeID = LZ4F_default;
}
- info.blockMode = FUZZ_dataProducer_uint32NonAdaptive(producer, LZ4F_blockLinked, LZ4F_blockIndependent);
- info.contentChecksumFlag = FUZZ_dataProducer_uint32NonAdaptive(producer, LZ4F_noContentChecksum,
+ info.blockMode = FUZZ_dataProducer_range32(producer, LZ4F_blockLinked, LZ4F_blockIndependent);
+ info.contentChecksumFlag = FUZZ_dataProducer_range32(producer, LZ4F_noContentChecksum,
LZ4F_contentChecksumEnabled);
- info.blockChecksumFlag = FUZZ_dataProducer_uint32NonAdaptive(producer, LZ4F_noBlockChecksum,
+ info.blockChecksumFlag = FUZZ_dataProducer_range32(producer, LZ4F_noBlockChecksum,
LZ4F_blockChecksumEnabled);
return info;
}
{
LZ4F_preferences_t prefs = LZ4F_INIT_PREFERENCES;
prefs.frameInfo = FUZZ_dataProducer_frameInfo(producer);
- prefs.compressionLevel = FUZZ_dataProducer_uint32NonAdaptive(producer, 0, LZ4HC_CLEVEL_MAX + 3) - 3;
- prefs.autoFlush = FUZZ_dataProducer_uint32NonAdaptive(producer, 0, 1);
- prefs.favorDecSpeed = FUZZ_dataProducer_uint32NonAdaptive(producer, 0, 1);
+ prefs.compressionLevel = FUZZ_dataProducer_range32(producer, 0, LZ4HC_CLEVEL_MAX + 3) - 3;
+ prefs.autoFlush = FUZZ_dataProducer_range32(producer, 0, 1);
+ prefs.favorDecSpeed = FUZZ_dataProducer_range32(producer, 0, 1);
return prefs;
}
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer);
/* Returns a seed value for the function after this one to consume */
-uint32_t FUZZ_dataProducer_uint32_seed(FUZZ_dataProducer_t *producer, uint32_t min,
+uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer, uint32_t min,
uint32_t max);
/* Returns value between [min, max] */
-uint32_t FUZZ_dataProducer_uint32(uint32_t seed, uint32_t min, uint32_t max);
+uint32_t FUZZ_getRange_from_uint32(uint32_t seed, uint32_t min, uint32_t max);
/* Combination of above two functions for non adaptive use cases. ie where size is not involved */
-uint32_t FUZZ_dataProducer_uint32NonAdaptive(FUZZ_dataProducer_t *producer, uint32_t min,
+uint32_t FUZZ_dataProducer_range32(FUZZ_dataProducer_t *producer, uint32_t min,
uint32_t max);
/* Returns lz4 preferences */
{
FUZZ_dataProducer_t* producer = FUZZ_dataProducer_create(data, size);
LZ4F_preferences_t const prefs = FUZZ_dataProducer_preferences(producer);
- size_t const dstCapacity = LZ4F_compressFrameBound(
- LZ4_compressBound(FUZZ_dataProducer_remainingBytes(producer)), &prefs);
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = LZ4F_compressFrameBound(LZ4_compressBound(size), &prefs);
+
char* const dst = (char*)malloc(dstCapacity);
char* const rt = (char*)malloc(FUZZ_dataProducer_remainingBytes(producer));
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);
- /* Restrict to remaining data from producer */
- size = FUZZ_dataProducer_remainingBytes(producer);
-
/* Compression must succeed and round trip correctly. */
size_t const dstSize =
LZ4F_compressFrame(dst, dstCapacity, data, size, &prefs);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- size_t const partialCapacitySeed = FUZZ_dataProducer_uint32_seed(producer, 0, size);
- size_t const partialCapacity = FUZZ_dataProducer_uint32(partialCapacitySeed,
- 0, FUZZ_dataProducer_remainingBytes(producer));
+ size_t const partialCapacitySeed = FUZZ_dataProducer_uint32(producer, 0, size);
+
+ size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const partialCapacity = FUZZ_getRange_from_uint32(partialCapacitySeed,
+ 0, size);
size_t const dstCapacity = LZ4_compressBound(size);
+
char* const dst = (char*)malloc(dstCapacity);
char* const rt = (char*)malloc(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);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
- int const level = FUZZ_dataProducer_uint32NonAdaptive(producer,
+ int const level = FUZZ_dataProducer_range32(producer,
LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
- size_t const dstCapacity = LZ4_compressBound(
- FUZZ_dataProducer_remainingBytes(producer));
- char* const dst = (char*)malloc(dstCapacity);
- char* const rt = (char*)malloc(size);
- /* Restrict to remaining data from producer */
size = FUZZ_dataProducer_remainingBytes(producer);
+ size_t const dstCapacity = LZ4_compressBound(size);
+
+ char* const dst = (char*)malloc(dstCapacity);
+ char* const rt = (char*)malloc(size);
FUZZ_ASSERT(dst);
FUZZ_ASSERT(rt);