Rizin
unix-like reverse engineering framework and cli tools
fuzz_data_producer.c File Reference

Go to the source code of this file.

Classes

struct  FUZZ_dataProducer_s
 

Functions

FUZZ_dataProducer_tFUZZ_dataProducer_create (const uint8_t *data, size_t size)
 
void FUZZ_dataProducer_free (FUZZ_dataProducer_t *producer)
 
uint32_t FUZZ_dataProducer_retrieve32 (FUZZ_dataProducer_t *producer)
 
uint32_t FUZZ_getRange_from_uint32 (uint32_t seed, uint32_t min, uint32_t max)
 
uint32_t FUZZ_dataProducer_range32 (FUZZ_dataProducer_t *producer, uint32_t min, uint32_t max)
 
LZ4F_frameInfo_t FUZZ_dataProducer_frameInfo (FUZZ_dataProducer_t *producer)
 
LZ4F_preferences_t FUZZ_dataProducer_preferences (FUZZ_dataProducer_t *producer)
 
size_t FUZZ_dataProducer_remainingBytes (FUZZ_dataProducer_t *producer)
 

Function Documentation

◆ FUZZ_dataProducer_create()

FUZZ_dataProducer_t* FUZZ_dataProducer_create ( const uint8_t data,
size_t  size 
)

Definition at line 8 of file fuzz_data_producer.c.

8  {
9  FUZZ_dataProducer_t* const producer = malloc(sizeof(FUZZ_dataProducer_t));
10 
11  FUZZ_ASSERT(producer != NULL);
12 
13  producer->data = data;
14  producer->size = size;
15  return producer;
16 }
#define NULL
Definition: cris-opc.c:27
#define FUZZ_ASSERT(cond)
Definition: fuzz_helpers.h:46
voidpf void uLong size
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
const uint8_t * data

References FUZZ_dataProducer_s::data, FUZZ_ASSERT, malloc(), NULL, and FUZZ_dataProducer_s::size.

Referenced by LLVMFuzzerTestOneInput().

◆ FUZZ_dataProducer_frameInfo()

LZ4F_frameInfo_t FUZZ_dataProducer_frameInfo ( FUZZ_dataProducer_t producer)

Definition at line 50 of file fuzz_data_producer.c.

51 {
53  info.blockSizeID = FUZZ_dataProducer_range32(producer, LZ4F_max64KB - 1, LZ4F_max4MB);
54  if (info.blockSizeID < LZ4F_max64KB) {
55  info.blockSizeID = LZ4F_default;
56  }
58  info.contentChecksumFlag = FUZZ_dataProducer_range32(producer, LZ4F_noContentChecksum,
60  info.blockChecksumFlag = FUZZ_dataProducer_range32(producer, LZ4F_noBlockChecksum,
62  return info;
63 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
uint32_t FUZZ_dataProducer_range32(FUZZ_dataProducer_t *producer, uint32_t min, uint32_t max)
@ LZ4F_blockLinked
Definition: lz4frame.h:139
@ LZ4F_blockIndependent
Definition: lz4frame.h:140
#define LZ4F_INIT_FRAMEINFO
Definition: lz4frame.h:185
@ LZ4F_default
Definition: lz4frame.h:124
@ LZ4F_max64KB
Definition: lz4frame.h:125
@ LZ4F_max4MB
Definition: lz4frame.h:128
@ LZ4F_noContentChecksum
Definition: lz4frame.h:146
@ LZ4F_contentChecksumEnabled
Definition: lz4frame.h:147
@ LZ4F_blockChecksumEnabled
Definition: lz4frame.h:154
@ LZ4F_noBlockChecksum
Definition: lz4frame.h:153

References FUZZ_dataProducer_range32(), info(), LZ4F_blockChecksumEnabled, LZ4F_blockIndependent, LZ4F_blockLinked, LZ4F_contentChecksumEnabled, LZ4F_default, LZ4F_INIT_FRAMEINFO, LZ4F_max4MB, LZ4F_max64KB, LZ4F_noBlockChecksum, and LZ4F_noContentChecksum.

Referenced by FUZZ_dataProducer_preferences().

◆ FUZZ_dataProducer_free()

void FUZZ_dataProducer_free ( FUZZ_dataProducer_t producer)

Definition at line 18 of file fuzz_data_producer.c.

18 { free(producer); }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free().

Referenced by LLVMFuzzerTestOneInput().

◆ FUZZ_dataProducer_preferences()

LZ4F_preferences_t FUZZ_dataProducer_preferences ( FUZZ_dataProducer_t producer)

Definition at line 65 of file fuzz_data_producer.c.

66 {
68  prefs.frameInfo = FUZZ_dataProducer_frameInfo(producer);
69  prefs.compressionLevel = FUZZ_dataProducer_range32(producer, 0, LZ4HC_CLEVEL_MAX + 3) - 3;
70  prefs.autoFlush = FUZZ_dataProducer_range32(producer, 0, 1);
71  prefs.favorDecSpeed = FUZZ_dataProducer_range32(producer, 0, 1);
72  return prefs;
73 }
LZ4F_frameInfo_t FUZZ_dataProducer_frameInfo(FUZZ_dataProducer_t *producer)
#define LZ4F_INIT_PREFERENCES
Definition: lz4frame.h:200
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.h:193
unsigned favorDecSpeed
Definition: lz4frame.h:196
unsigned autoFlush
Definition: lz4frame.h:195

References LZ4F_preferences_t::autoFlush, LZ4F_preferences_t::compressionLevel, LZ4F_preferences_t::favorDecSpeed, LZ4F_preferences_t::frameInfo, FUZZ_dataProducer_frameInfo(), FUZZ_dataProducer_range32(), LZ4F_INIT_PREFERENCES, and LZ4HC_CLEVEL_MAX.

Referenced by LLVMFuzzerTestOneInput().

◆ FUZZ_dataProducer_range32()

uint32_t FUZZ_dataProducer_range32 ( FUZZ_dataProducer_t producer,
uint32_t  min,
uint32_t  max 
)

Definition at line 43 of file fuzz_data_producer.c.

45 {
46  size_t const seed = FUZZ_dataProducer_retrieve32(producer);
47  return FUZZ_getRange_from_uint32(seed, min, max);
48 }
int max
Definition: enough.c:225
uint32_t FUZZ_getRange_from_uint32(uint32_t seed, uint32_t min, uint32_t max)
uint32_t FUZZ_dataProducer_retrieve32(FUZZ_dataProducer_t *producer)
#define min(a, b)
Definition: qsort.h:83

References FUZZ_dataProducer_retrieve32(), FUZZ_getRange_from_uint32(), max, and min.

Referenced by FUZZ_dataProducer_frameInfo(), FUZZ_dataProducer_preferences(), and LLVMFuzzerTestOneInput().

◆ FUZZ_dataProducer_remainingBytes()

size_t FUZZ_dataProducer_remainingBytes ( FUZZ_dataProducer_t producer)

Definition at line 75 of file fuzz_data_producer.c.

75  {
76  return producer->size;
77 }

References FUZZ_dataProducer_s::size.

Referenced by LLVMFuzzerTestOneInput().

◆ FUZZ_dataProducer_retrieve32()

uint32_t FUZZ_dataProducer_retrieve32 ( FUZZ_dataProducer_t producer)

Definition at line 20 of file fuzz_data_producer.c.

20  {
21  const uint8_t* data = producer->data;
22  const size_t size = producer->size;
23  if (size == 0) {
24  return 0;
25  } else if (size < 4) {
26  producer->size -= 1;
27  return (uint32_t)data[size - 1];
28  } else {
29  producer->size -= 4;
30  return *(data + size - 4);
31  }
32 }
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31

References FUZZ_dataProducer_s::data, and FUZZ_dataProducer_s::size.

Referenced by FUZZ_dataProducer_range32(), and LLVMFuzzerTestOneInput().

◆ FUZZ_getRange_from_uint32()

uint32_t FUZZ_getRange_from_uint32 ( uint32_t  seed,
uint32_t  min,
uint32_t  max 
)

Definition at line 34 of file fuzz_data_producer.c.

35 {
36  uint32_t range = max - min;
37  if (range == 0xffffffff) {
38  return seed;
39  }
40  return min + seed % (range + 1);
41 }

References max, min, and capstone::range.

Referenced by FUZZ_dataProducer_range32(), and LLVMFuzzerTestOneInput().