Rizin
unix-like reverse engineering framework and cli tools
round_trip_hc_fuzzer.c
Go to the documentation of this file.
1 
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "fuzz_helpers.h"
12 #include "fuzz_data_producer.h"
13 #include "lz4.h"
14 #include "lz4hc.h"
15 
16 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17 {
19  int const level = FUZZ_dataProducer_range32(producer,
22 
23  size_t const dstCapacity = LZ4_compressBound(size);
24  char* const dst = (char*)malloc(dstCapacity);
25  char* const rt = (char*)malloc(size);
26 
28  FUZZ_ASSERT(rt);
29 
30  /* Compression must succeed and round trip correctly. */
31  int const dstSize = LZ4_compress_HC((const char*)data, dst, size,
32  dstCapacity, level);
33  FUZZ_ASSERT(dstSize > 0);
34 
35  int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
36  FUZZ_ASSERT_MSG(rtSize == size, "Incorrect size");
37  FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
38 
39  free(dst);
40  free(rt);
41  FUZZ_dataProducer_free(producer);
42 
43  return 0;
44 }
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer)
size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer)
uint32_t FUZZ_dataProducer_range32(FUZZ_dataProducer_t *producer, uint32_t min, uint32_t max)
FUZZ_dataProducer_t * FUZZ_dataProducer_create(const uint8_t *data, size_t size)
#define FUZZ_ASSERT(cond)
Definition: fuzz_helpers.h:46
#define FUZZ_ASSERT_MSG(cond, msg)
Definition: fuzz_helpers.h:41
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
int LZ4_compressBound(int isize)
Definition: lz4.c:674
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
Definition: lz4.c:2171
char * dst
Definition: lz4.h:724
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition: lz4hc.c:954
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
#define LZ4HC_CLEVEL_MIN
Definition: lz4hc.h:47
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
unsigned char uint8_t
Definition: sftypes.h:31
static int level
Definition: vmenus.c:2424