Rizin
unix-like reverse engineering framework and cli tools
lz4_helpers.c
Go to the documentation of this file.
1 #include "fuzz_helpers.h"
2 #include "lz4_helpers.h"
3 #include "lz4hc.h"
4 
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 }
19 
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 }
29 
30 size_t FUZZ_decompressFrame(void* dst, const size_t dstCapacity,
31  const void* src, const size_t srcSize)
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
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
#define FUZZ_ASSERT(cond)
Definition: fuzz_helpers.h:46
FUZZ_STATIC uint32_t FUZZ_rand32(uint32_t *state, uint32_t min, uint32_t max)
Definition: fuzz_helpers.h:85
return memset(p, 0, total)
char int srcSize
Definition: lz4.h:697
char * dst
Definition: lz4.h:724
LZ4F_frameInfo_t FUZZ_randomFrameInfo(uint32_t *seed)
Definition: lz4_helpers.c:5
LZ4F_preferences_t FUZZ_randomPreferences(uint32_t *seed)
Definition: lz4_helpers.c:20
size_t FUZZ_decompressFrame(void *dst, const size_t dstCapacity, const void *src, const size_t srcSize)
Definition: lz4_helpers.c:30
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
@ 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
#define LZ4F_INIT_PREFERENCES
Definition: lz4frame.h:200
@ LZ4F_noContentChecksum
Definition: lz4frame.h:146
@ LZ4F_contentChecksumEnabled
Definition: lz4frame.h:147
@ LZ4F_blockChecksumEnabled
Definition: lz4frame.h:154
@ LZ4F_noBlockChecksum
Definition: lz4frame.h:153
#define LZ4F_VERSION
Definition: lz4frame.h:242
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
unsigned int uint32_t
Definition: sftypes.h:29
LZ4F_frameInfo_t frameInfo
Definition: lz4frame.h:193
unsigned favorDecSpeed
Definition: lz4frame.h:196
unsigned autoFlush
Definition: lz4frame.h:195