Rizin
unix-like reverse engineering framework and cli tools
decompress_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 "fuzz_data_producer.h"
13 #include "lz4.h"
14 #define LZ4F_STATIC_LINKING_ONLY
15 #include "lz4frame.h"
16 #include "lz4_helpers.h"
17 
18 static void decompress(LZ4F_dctx* dctx, void* dst, size_t dstCapacity,
19  const void* src, size_t srcSize,
20  const void* dict, size_t dictSize,
21  const LZ4F_decompressOptions_t* opts)
22 {
24  if (dictSize == 0)
25  LZ4F_decompress(dctx, dst, &dstCapacity, src, &srcSize, opts);
26  else
27  LZ4F_decompress_usingDict(dctx, dst, &dstCapacity, src, &srcSize,
28  dict, dictSize, opts);
29 }
30 
31 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
32 {
34  size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
35  size_t const dictSizeSeed = FUZZ_dataProducer_retrieve32(producer);
37 
38  size_t const dstCapacity = FUZZ_getRange_from_uint32(
39  dstCapacitySeed, 0, 4 * size);
40  size_t const largeDictSize = 64 * 1024;
41  size_t const dictSize = FUZZ_getRange_from_uint32(
42  dictSizeSeed, 0, largeDictSize);
43 
44  char* const dst = (char*)malloc(dstCapacity);
45  char* const dict = (char*)malloc(dictSize);
47  LZ4F_dctx* dctx;
49 
50  FUZZ_ASSERT(dctx);
52  FUZZ_ASSERT(dict);
53 
54  /* Prepare the dictionary. The data doesn't matter for decompression. */
55  memset(dict, 0, dictSize);
56 
57 
58  /* Decompress using multiple configurations. */
59  memset(&opts, 0, sizeof(opts));
60  opts.stableDst = 0;
61  decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
62  opts.stableDst = 1;
63  decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
64  opts.stableDst = 0;
65  decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
66  opts.stableDst = 1;
67  decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
68 
70  free(dst);
71  free(dict);
72  FUZZ_dataProducer_free(producer);
73 
74  return 0;
75 }
lzma_index * src
Definition: index.h:567
#define NULL
Definition: cris-opc.c:27
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static void decompress(LZ4F_dctx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const LZ4F_decompressOptions_t *opts)
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)
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
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
char int srcSize
Definition: lz4.h:697
char * dst
Definition: lz4.h:724
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:1082
size_t LZ4F_decompress_usingDict(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const void *dict, size_t dictSize, const LZ4F_decompressOptions_t *decompressOptionsPtr)
Definition: lz4frame.c:1886
size_t LZ4F_decompress(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
Definition: lz4frame.c:1384
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
Definition: lz4frame.c:1069
void LZ4F_resetDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:1097
#define LZ4F_VERSION
Definition: lz4frame.h:242
unsigned char uint8_t
Definition: sftypes.h:31