Rizin
unix-like reverse engineering framework and cli tools
fuzz_data_producer.c
Go to the documentation of this file.
1 #include "fuzz_data_producer.h"
2 
4  const uint8_t *data;
5  size_t size;
6 };
7 
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 }
17 
18 void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer) { free(producer); }
19 
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 }
33 
35 {
36  uint32_t range = max - min;
37  if (range == 0xffffffff) {
38  return seed;
39  }
40  return min + seed % (range + 1);
41 }
42 
45 {
46  size_t const seed = FUZZ_dataProducer_retrieve32(producer);
47  return FUZZ_getRange_from_uint32(seed, min, max);
48 }
49 
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 }
64 
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 }
74 
76  return producer->size;
77 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
#define NULL
Definition: cris-opc.c:27
int max
Definition: enough.c:225
LZ4F_frameInfo_t FUZZ_dataProducer_frameInfo(FUZZ_dataProducer_t *producer)
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer)
uint32_t FUZZ_getRange_from_uint32(uint32_t seed, uint32_t min, uint32_t max)
size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer)
uint32_t FUZZ_dataProducer_range32(FUZZ_dataProducer_t *producer, uint32_t min, uint32_t max)
LZ4F_preferences_t FUZZ_dataProducer_preferences(FUZZ_dataProducer_t *producer)
FUZZ_dataProducer_t * FUZZ_dataProducer_create(const uint8_t *data, size_t size)
uint32_t FUZZ_dataProducer_retrieve32(FUZZ_dataProducer_t *producer)
#define FUZZ_ASSERT(cond)
Definition: fuzz_helpers.h:46
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
@ 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
#define LZ4F_INIT_PREFERENCES
Definition: lz4frame.h:200
@ LZ4F_noContentChecksum
Definition: lz4frame.h:146
@ LZ4F_contentChecksumEnabled
Definition: lz4frame.h:147
@ LZ4F_blockChecksumEnabled
Definition: lz4frame.h:154
@ LZ4F_noBlockChecksum
Definition: lz4frame.h:153
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
#define min(a, b)
Definition: qsort.h:83
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
const uint8_t * data
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.h:193
unsigned favorDecSpeed
Definition: lz4frame.h:196
unsigned autoFlush
Definition: lz4frame.h:195