Rizin
unix-like reverse engineering framework and cli tools
lz4_helpers.c File Reference
#include "fuzz_helpers.h"
#include "lz4_helpers.h"
#include "lz4hc.h"

Go to the source code of this file.

Functions

LZ4F_frameInfo_t FUZZ_randomFrameInfo (uint32_t *seed)
 
LZ4F_preferences_t FUZZ_randomPreferences (uint32_t *seed)
 
size_t FUZZ_decompressFrame (void *dst, const size_t dstCapacity, const void *src, const size_t srcSize)
 

Function Documentation

◆ FUZZ_decompressFrame()

size_t FUZZ_decompressFrame ( void *  dst,
const size_t  dstCapacity,
const void *  src,
const size_t  srcSize 
)

Definition at line 30 of file lz4_helpers.c.

32 {
34  memset(&opts, 0, sizeof(opts));
35  opts.stableDst = 1;
36  LZ4F_dctx* dctx;
38  FUZZ_ASSERT(dctx);
39 
40  size_t dstSize = dstCapacity;
41  size_t srcConsumed = srcSize;
42  size_t const rc =
43  LZ4F_decompress(dctx, dst, &dstSize, src, &srcConsumed, &opts);
45  FUZZ_ASSERT(rc == 0);
46  FUZZ_ASSERT(srcConsumed == srcSize);
47 
49 
50  return dstSize;
51 }
lzma_index * src
Definition: index.h:567
#define FUZZ_ASSERT(cond)
Definition: fuzz_helpers.h:46
return memset(p, 0, total)
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(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
Definition: lz4frame.c:1384
unsigned LZ4F_isError(LZ4F_errorCode_t code)
Definition: lz4frame.c:249
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
Definition: lz4frame.c:1069
#define LZ4F_VERSION
Definition: lz4frame.h:242

References dst, FUZZ_ASSERT, LZ4F_createDecompressionContext(), LZ4F_decompress(), LZ4F_freeDecompressionContext(), LZ4F_isError(), LZ4F_VERSION, memset(), src, srcSize, and LZ4F_decompressOptions_t::stableDst.

Referenced by LLVMFuzzerTestOneInput().

◆ FUZZ_randomFrameInfo()

LZ4F_frameInfo_t FUZZ_randomFrameInfo ( uint32_t seed)

Definition at line 5 of file lz4_helpers.c.

6 {
8  info.blockSizeID = FUZZ_rand32(seed, LZ4F_max64KB - 1, LZ4F_max4MB);
9  if (info.blockSizeID < LZ4F_max64KB) {
10  info.blockSizeID = LZ4F_default;
11  }
13  info.contentChecksumFlag = FUZZ_rand32(seed, LZ4F_noContentChecksum,
15  info.blockChecksumFlag = FUZZ_rand32(seed, LZ4F_noBlockChecksum,
17  return info;
18 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
FUZZ_STATIC uint32_t FUZZ_rand32(uint32_t *state, uint32_t min, uint32_t max)
Definition: fuzz_helpers.h:85
@ 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
@ LZ4F_noContentChecksum
Definition: lz4frame.h:146
@ LZ4F_contentChecksumEnabled
Definition: lz4frame.h:147
@ LZ4F_blockChecksumEnabled
Definition: lz4frame.h:154
@ LZ4F_noBlockChecksum
Definition: lz4frame.h:153

References FUZZ_rand32(), info(), LZ4F_blockChecksumEnabled, LZ4F_blockIndependent, LZ4F_blockLinked, LZ4F_contentChecksumEnabled, LZ4F_default, LZ4F_INIT_FRAMEINFO, LZ4F_max4MB, LZ4F_max64KB, LZ4F_noBlockChecksum, and LZ4F_noContentChecksum.

Referenced by FUZZ_randomPreferences().

◆ FUZZ_randomPreferences()

LZ4F_preferences_t FUZZ_randomPreferences ( uint32_t seed)

Definition at line 20 of file lz4_helpers.c.

21 {
23  prefs.frameInfo = FUZZ_randomFrameInfo(seed);
24  prefs.compressionLevel = FUZZ_rand32(seed, 0, LZ4HC_CLEVEL_MAX + 3) - 3;
25  prefs.autoFlush = FUZZ_rand32(seed, 0, 1);
26  prefs.favorDecSpeed = FUZZ_rand32(seed, 0, 1);
27  return prefs;
28 }
LZ4F_frameInfo_t FUZZ_randomFrameInfo(uint32_t *seed)
Definition: lz4_helpers.c:5
#define LZ4F_INIT_PREFERENCES
Definition: lz4frame.h:200
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.h:193
unsigned favorDecSpeed
Definition: lz4frame.h:196
unsigned autoFlush
Definition: lz4frame.h:195

References LZ4F_preferences_t::autoFlush, LZ4F_preferences_t::compressionLevel, LZ4F_preferences_t::favorDecSpeed, LZ4F_preferences_t::frameInfo, FUZZ_rand32(), FUZZ_randomFrameInfo(), LZ4F_INIT_PREFERENCES, and LZ4HC_CLEVEL_MAX.