Rizin
unix-like reverse engineering framework and cli tools
decompress_frame_fuzzer.c File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "fuzz_helpers.h"
#include "fuzz_data_producer.h"
#include "lz4.h"
#include "lz4frame.h"
#include "lz4_helpers.h"

Go to the source code of this file.

Macros

#define LZ4F_STATIC_LINKING_ONLY
 

Functions

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)
 
int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
 

Macro Definition Documentation

◆ LZ4F_STATIC_LINKING_ONLY

#define LZ4F_STATIC_LINKING_ONLY

This fuzz target attempts to decompress the fuzzed data with the simple decompression function to ensure the decompressor never crashes.

Definition at line 14 of file decompress_frame_fuzzer.c.

Function Documentation

◆ decompress()

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 
)
static

Definition at line 18 of file decompress_frame_fuzzer.c.

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 }
lzma_index * src
Definition: index.h:567
char int srcSize
Definition: lz4.h:697
char * dst
Definition: lz4.h:724
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
void LZ4F_resetDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:1097

References dst, LZ4F_decompress(), LZ4F_decompress_usingDict(), LZ4F_resetDecompressionContext(), src, and srcSize.

Referenced by LLVMFuzzerTestOneInput().

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t data,
size_t  size 
)

This fuzz target attempts to compress the fuzzed data with the simple compression function with an output buffer that may be too small to ensure that the compressor never crashes.

Definition at line 31 of file decompress_frame_fuzzer.c.

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 }
#define NULL
Definition: cris-opc.c:27
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
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:1082
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
Definition: lz4frame.c:1069
#define LZ4F_VERSION
Definition: lz4frame.h:242

References decompress(), dst, free(), FUZZ_ASSERT, FUZZ_dataProducer_create(), FUZZ_dataProducer_free(), FUZZ_dataProducer_remainingBytes(), FUZZ_dataProducer_retrieve32(), FUZZ_getRange_from_uint32(), LZ4F_createDecompressionContext(), LZ4F_freeDecompressionContext(), LZ4F_VERSION, malloc(), memset(), NULL, and LZ4F_decompressOptions_t::stableDst.