Rizin
unix-like reverse engineering framework and cli tools
round_trip_frame_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 "lz4.h"
13 #include "lz4frame.h"
14 #include "lz4_helpers.h"
15 #include "fuzz_data_producer.h"
16 
17 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
18 {
20  LZ4F_preferences_t const prefs = FUZZ_dataProducer_preferences(producer);
22 
23  size_t const dstCapacity = LZ4F_compressFrameBound(LZ4_compressBound(size), &prefs);
24  char* const dst = (char*)malloc(dstCapacity);
25  char* const rt = (char*)malloc(FUZZ_dataProducer_remainingBytes(producer));
26 
28  FUZZ_ASSERT(rt);
29 
30  /* Compression must succeed and round trip correctly. */
31  size_t const dstSize =
32  LZ4F_compressFrame(dst, dstCapacity, data, size, &prefs);
33  FUZZ_ASSERT(!LZ4F_isError(dstSize));
34  size_t const rtSize = FUZZ_decompressFrame(rt, size, dst, dstSize);
35  FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
36  FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
37 
38  free(dst);
39  free(rt);
40  FUZZ_dataProducer_free(producer);
41 
42  return 0;
43 }
void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer)
size_t FUZZ_dataProducer_remainingBytes(FUZZ_dataProducer_t *producer)
LZ4F_preferences_t FUZZ_dataProducer_preferences(FUZZ_dataProducer_t *producer)
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
char * dst
Definition: lz4.h:724
size_t FUZZ_decompressFrame(void *dst, const size_t dstCapacity, const void *src, const size_t srcSize)
Definition: lz4_helpers.c:30
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:351
unsigned LZ4F_isError(LZ4F_errorCode_t code)
Definition: lz4frame.c:249
size_t LZ4F_compressFrame(void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:429
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
unsigned char uint8_t
Definition: sftypes.h:31