/src/lz4/ossfuzz/lz4_helpers.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "fuzz_helpers.h" |
2 | | #include "lz4_helpers.h" |
3 | | #include "lz4hc.h" |
4 | | |
5 | | LZ4F_frameInfo_t FUZZ_randomFrameInfo(uint32_t* seed) |
6 | 0 | { |
7 | 0 | LZ4F_frameInfo_t info = LZ4F_INIT_FRAMEINFO; |
8 | 0 | info.blockSizeID = FUZZ_rand32(seed, LZ4F_max64KB - 1, LZ4F_max4MB); |
9 | 0 | if (info.blockSizeID < LZ4F_max64KB) { |
10 | 0 | info.blockSizeID = LZ4F_default; |
11 | 0 | } |
12 | 0 | info.blockMode = FUZZ_rand32(seed, LZ4F_blockLinked, LZ4F_blockIndependent); |
13 | 0 | info.contentChecksumFlag = FUZZ_rand32(seed, LZ4F_noContentChecksum, |
14 | 0 | LZ4F_contentChecksumEnabled); |
15 | 0 | info.blockChecksumFlag = FUZZ_rand32(seed, LZ4F_noBlockChecksum, |
16 | 0 | LZ4F_blockChecksumEnabled); |
17 | 0 | return info; |
18 | 0 | } |
19 | | |
20 | | LZ4F_preferences_t FUZZ_randomPreferences(uint32_t* seed) |
21 | 0 | { |
22 | 0 | LZ4F_preferences_t prefs = LZ4F_INIT_PREFERENCES; |
23 | 0 | prefs.frameInfo = FUZZ_randomFrameInfo(seed); |
24 | 0 | prefs.compressionLevel = FUZZ_rand32(seed, 0, LZ4HC_CLEVEL_MAX + 3) - 3; |
25 | 0 | prefs.autoFlush = FUZZ_rand32(seed, 0, 1); |
26 | 0 | prefs.favorDecSpeed = FUZZ_rand32(seed, 0, 1); |
27 | 0 | return prefs; |
28 | 0 | } |
29 | | |
30 | | size_t FUZZ_decompressFrame(void* dst, const size_t dstCapacity, |
31 | | const void* src, const size_t srcSize) |
32 | 6.34k | { |
33 | 6.34k | LZ4F_decompressOptions_t opts; |
34 | 6.34k | memset(&opts, 0, sizeof(opts)); |
35 | 6.34k | opts.stableDst = 1; |
36 | 6.34k | LZ4F_dctx* dctx; |
37 | 6.34k | LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION); |
38 | 6.34k | FUZZ_ASSERT(dctx); |
39 | | |
40 | 6.34k | size_t dstSize = dstCapacity; |
41 | 6.34k | size_t srcConsumed = srcSize; |
42 | 6.34k | size_t const rc = |
43 | 6.34k | LZ4F_decompress(dctx, dst, &dstSize, src, &srcConsumed, &opts); |
44 | 6.34k | FUZZ_ASSERT(!LZ4F_isError(rc)); |
45 | 6.34k | FUZZ_ASSERT(rc == 0); |
46 | 6.34k | FUZZ_ASSERT(srcConsumed == srcSize); |
47 | | |
48 | 6.34k | LZ4F_freeDecompressionContext(dctx); |
49 | | |
50 | 6.34k | return dstSize; |
51 | 6.34k | } |