extlz4 0.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja.md +7 -0
  3. data/README.md +3 -3
  4. data/contrib/lz4/Makefile.inc +87 -0
  5. data/contrib/lz4/NEWS +7 -0
  6. data/contrib/lz4/README.md +1 -1
  7. data/contrib/lz4/lib/README.md +3 -5
  8. data/contrib/lz4/lib/liblz4-dll.rc.in +35 -0
  9. data/contrib/lz4/lib/lz4.c +296 -182
  10. data/contrib/lz4/lib/lz4.h +125 -40
  11. data/contrib/lz4/lib/lz4frame.c +30 -6
  12. data/contrib/lz4/lib/lz4frame.h +11 -2
  13. data/contrib/lz4/lib/lz4hc.c +93 -30
  14. data/contrib/lz4/lib/lz4hc.h +3 -0
  15. data/contrib/lz4/ossfuzz/Makefile +74 -0
  16. data/contrib/lz4/ossfuzz/compress_frame_fuzzer.c +42 -0
  17. data/contrib/lz4/ossfuzz/compress_fuzzer.c +51 -0
  18. data/contrib/lz4/ossfuzz/compress_hc_fuzzer.c +57 -0
  19. data/contrib/lz4/ossfuzz/decompress_frame_fuzzer.c +67 -0
  20. data/contrib/lz4/ossfuzz/decompress_fuzzer.c +58 -0
  21. data/contrib/lz4/ossfuzz/fuzz.h +48 -0
  22. data/contrib/lz4/ossfuzz/fuzz_helpers.h +94 -0
  23. data/contrib/lz4/ossfuzz/lz4_helpers.c +51 -0
  24. data/contrib/lz4/ossfuzz/lz4_helpers.h +13 -0
  25. data/contrib/lz4/ossfuzz/ossfuzz.sh +23 -0
  26. data/contrib/lz4/ossfuzz/round_trip_frame_fuzzer.c +39 -0
  27. data/contrib/lz4/ossfuzz/round_trip_fuzzer.c +50 -0
  28. data/contrib/lz4/ossfuzz/round_trip_hc_fuzzer.c +39 -0
  29. data/contrib/lz4/ossfuzz/round_trip_stream_fuzzer.c +302 -0
  30. data/contrib/lz4/ossfuzz/standaloneengine.c +74 -0
  31. data/contrib/lz4/ossfuzz/travisoss.sh +21 -0
  32. data/ext/blockapi.c +3 -3
  33. data/ext/hashargs.c +1 -1
  34. data/lib/extlz4.rb +5 -1
  35. data/lib/extlz4/version.rb +1 -1
  36. data/test/common.rb +2 -2
  37. metadata +22 -3
@@ -336,6 +336,9 @@ LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionL
336
336
  #ifndef LZ4_HC_SLO_098092834
337
337
  #define LZ4_HC_SLO_098092834
338
338
 
339
+ #define LZ4_STATIC_LINKING_ONLY /* LZ4LIB_STATIC_API */
340
+ #include "lz4.h"
341
+
339
342
  #if defined (__cplusplus)
340
343
  extern "C" {
341
344
  #endif
@@ -0,0 +1,74 @@
1
+ # ##########################################################################
2
+ # LZ4 oss fuzzer - Makefile
3
+ #
4
+ # GPL v2 License
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with this program; if not, write to the Free Software Foundation, Inc.,
18
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ #
20
+ # You can contact the author at :
21
+ # - LZ4 homepage : http://www.lz4.org
22
+ # - LZ4 source repository : https://github.com/lz4/lz4
23
+ # ##########################################################################
24
+ # compress_fuzzer : OSS Fuzz test tool
25
+ # decompress_fuzzer : OSS Fuzz test tool
26
+ # ##########################################################################
27
+
28
+ LZ4DIR := ../lib
29
+ LIB_FUZZING_ENGINE ?= standaloneengine.o
30
+
31
+ DEBUGLEVEL?= 1
32
+ DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
33
+
34
+ LZ4_CFLAGS = $(CFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
35
+ LZ4_CXXFLAGS = $(CXXFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
36
+ LZ4_CPPFLAGS = $(CPPFLAGS) -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ \
37
+ -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
38
+
39
+ FUZZERS := \
40
+ compress_fuzzer \
41
+ decompress_fuzzer \
42
+ round_trip_fuzzer \
43
+ round_trip_stream_fuzzer \
44
+ compress_hc_fuzzer \
45
+ round_trip_hc_fuzzer \
46
+ compress_frame_fuzzer \
47
+ round_trip_frame_fuzzer \
48
+ decompress_frame_fuzzer
49
+
50
+ all: $(FUZZERS)
51
+
52
+ # Include a rule to build the static library if calling this target
53
+ # directly.
54
+ $(LZ4DIR)/liblz4.a:
55
+ $(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
56
+
57
+ %.o: %.c
58
+ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
59
+
60
+ # Generic rule for generating fuzzers
61
+ %_fuzzer: %_fuzzer.o lz4_helpers.o $(LZ4DIR)/liblz4.a
62
+ # Compile the standalone code just in case. The OSS-Fuzz code might
63
+ # override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer"
64
+ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) standaloneengine.c -o standaloneengine.o
65
+
66
+ # Now compile the actual fuzzer.
67
+ $(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
68
+
69
+ %_fuzzer_clean:
70
+ $(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o
71
+
72
+ .PHONY: clean
73
+ clean: compress_fuzzer_clean decompress_fuzzer_clean
74
+ $(MAKE) -C $(LZ4DIR) clean
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This fuzz target attempts to compress the fuzzed data with the simple
3
+ * compression function with an output buffer that may be too small to
4
+ * ensure that the compressor never crashes.
5
+ */
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "fuzz_helpers.h"
13
+ #include "lz4.h"
14
+ #include "lz4frame.h"
15
+ #include "lz4_helpers.h"
16
+
17
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
18
+ {
19
+ uint32_t seed = FUZZ_seed(&data, &size);
20
+ LZ4F_preferences_t const prefs = FUZZ_randomPreferences(&seed);
21
+ size_t const compressBound = LZ4F_compressFrameBound(size, &prefs);
22
+ size_t const dstCapacity = FUZZ_rand32(&seed, 0, compressBound);
23
+ char* const dst = (char*)malloc(dstCapacity);
24
+ char* const rt = (char*)malloc(size);
25
+
26
+ FUZZ_ASSERT(dst);
27
+ FUZZ_ASSERT(rt);
28
+
29
+ /* If compression succeeds it must round trip correctly. */
30
+ size_t const dstSize =
31
+ LZ4F_compressFrame(dst, dstCapacity, data, size, &prefs);
32
+ if (!LZ4F_isError(dstSize)) {
33
+ size_t const rtSize = FUZZ_decompressFrame(rt, size, dst, dstSize);
34
+ FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
35
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
36
+ }
37
+
38
+ free(dst);
39
+ free(rt);
40
+
41
+ return 0;
42
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * This fuzz target attempts to compress the fuzzed data with the simple
3
+ * compression function with an output buffer that may be too small to
4
+ * ensure that the compressor never crashes.
5
+ */
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "fuzz_helpers.h"
13
+ #include "lz4.h"
14
+
15
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
16
+ {
17
+ uint32_t seed = FUZZ_seed(&data, &size);
18
+ size_t const dstCapacity = FUZZ_rand32(&seed, 0, LZ4_compressBound(size));
19
+ char* const dst = (char*)malloc(dstCapacity);
20
+ char* const rt = (char*)malloc(size);
21
+
22
+ FUZZ_ASSERT(dst);
23
+ FUZZ_ASSERT(rt);
24
+
25
+ /* If compression succeeds it must round trip correctly. */
26
+ {
27
+ int const dstSize = LZ4_compress_default((const char*)data, dst,
28
+ size, dstCapacity);
29
+ if (dstSize > 0) {
30
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
31
+ FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
32
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
33
+ }
34
+ }
35
+
36
+ if (dstCapacity > 0) {
37
+ /* Compression succeeds and must round trip correctly. */
38
+ int compressedSize = size;
39
+ int const dstSize = LZ4_compress_destSize((const char*)data, dst,
40
+ &compressedSize, dstCapacity);
41
+ FUZZ_ASSERT(dstSize > 0);
42
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
43
+ FUZZ_ASSERT_MSG(rtSize == compressedSize, "Incorrect regenerated size");
44
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, compressedSize), "Corruption!");
45
+ }
46
+
47
+ free(dst);
48
+ free(rt);
49
+
50
+ return 0;
51
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * This fuzz target attempts to compress the fuzzed data with the simple
3
+ * compression function with an output buffer that may be too small to
4
+ * ensure that the compressor never crashes.
5
+ */
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #include "fuzz_helpers.h"
13
+ #include "lz4.h"
14
+ #include "lz4hc.h"
15
+
16
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17
+ {
18
+ uint32_t seed = FUZZ_seed(&data, &size);
19
+ size_t const dstCapacity = FUZZ_rand32(&seed, 0, LZ4_compressBound(size));
20
+ char* const dst = (char*)malloc(dstCapacity);
21
+ char* const rt = (char*)malloc(size);
22
+ int const level = FUZZ_rand32(&seed, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
23
+
24
+ FUZZ_ASSERT(dst);
25
+ FUZZ_ASSERT(rt);
26
+
27
+ /* If compression succeeds it must round trip correctly. */
28
+ {
29
+ int const dstSize = LZ4_compress_HC((const char*)data, dst, size,
30
+ dstCapacity, level);
31
+ if (dstSize > 0) {
32
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
33
+ FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
34
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
35
+ }
36
+ }
37
+
38
+ if (dstCapacity > 0) {
39
+ /* Compression succeeds and must round trip correctly. */
40
+ void* state = malloc(LZ4_sizeofStateHC());
41
+ FUZZ_ASSERT(state);
42
+ int compressedSize = size;
43
+ int const dstSize = LZ4_compress_HC_destSize(state, (const char*)data,
44
+ dst, &compressedSize,
45
+ dstCapacity, level);
46
+ FUZZ_ASSERT(dstSize > 0);
47
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
48
+ FUZZ_ASSERT_MSG(rtSize == compressedSize, "Incorrect regenerated size");
49
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, compressedSize), "Corruption!");
50
+ free(state);
51
+ }
52
+
53
+ free(dst);
54
+ free(rt);
55
+
56
+ return 0;
57
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This fuzz target attempts to decompress the fuzzed data with the simple
3
+ * decompression function to ensure the decompressor never crashes.
4
+ */
5
+
6
+ #include <stddef.h>
7
+ #include <stdint.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+
11
+ #include "fuzz_helpers.h"
12
+ #include "lz4.h"
13
+ #define LZ4F_STATIC_LINKING_ONLY
14
+ #include "lz4frame.h"
15
+ #include "lz4_helpers.h"
16
+
17
+ static void decompress(LZ4F_dctx* dctx, void* dst, size_t dstCapacity,
18
+ const void* src, size_t srcSize,
19
+ const void* dict, size_t dictSize,
20
+ const LZ4F_decompressOptions_t* opts)
21
+ {
22
+ LZ4F_resetDecompressionContext(dctx);
23
+ if (dictSize == 0)
24
+ LZ4F_decompress(dctx, dst, &dstCapacity, src, &srcSize, opts);
25
+ else
26
+ LZ4F_decompress_usingDict(dctx, dst, &dstCapacity, src, &srcSize,
27
+ dict, dictSize, opts);
28
+ }
29
+
30
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
31
+ {
32
+
33
+ uint32_t seed = FUZZ_seed(&data, &size);
34
+ size_t const dstCapacity = FUZZ_rand32(&seed, 0, 4 * size);
35
+ size_t const largeDictSize = 64 * 1024;
36
+ size_t const dictSize = FUZZ_rand32(&seed, 0, largeDictSize);
37
+ char* const dst = (char*)malloc(dstCapacity);
38
+ char* const dict = (char*)malloc(dictSize);
39
+ LZ4F_decompressOptions_t opts;
40
+ LZ4F_dctx* dctx;
41
+ LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
42
+
43
+ FUZZ_ASSERT(dctx);
44
+ FUZZ_ASSERT(dst);
45
+ FUZZ_ASSERT(dict);
46
+
47
+ /* Prepare the dictionary. The data doesn't matter for decompression. */
48
+ memset(dict, 0, dictSize);
49
+
50
+
51
+ /* Decompress using multiple configurations. */
52
+ memset(&opts, 0, sizeof(opts));
53
+ opts.stableDst = 0;
54
+ decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
55
+ opts.stableDst = 1;
56
+ decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
57
+ opts.stableDst = 0;
58
+ decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
59
+ opts.stableDst = 1;
60
+ decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
61
+
62
+ LZ4F_freeDecompressionContext(dctx);
63
+ free(dst);
64
+ free(dict);
65
+
66
+ return 0;
67
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * This fuzz target attempts to decompress the fuzzed data with the simple
3
+ * decompression function to ensure the decompressor never crashes.
4
+ */
5
+
6
+ #include <stddef.h>
7
+ #include <stdint.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+
11
+ #include "fuzz_helpers.h"
12
+ #include "lz4.h"
13
+
14
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
15
+ {
16
+
17
+ uint32_t seed = FUZZ_seed(&data, &size);
18
+ size_t const dstCapacity = FUZZ_rand32(&seed, 0, 4 * size);
19
+ size_t const smallDictSize = size + 1;
20
+ size_t const largeDictSize = 64 * 1024 - 1;
21
+ size_t const dictSize = MAX(smallDictSize, largeDictSize);
22
+ char* const dst = (char*)malloc(dstCapacity);
23
+ char* const dict = (char*)malloc(dictSize + size);
24
+ char* const largeDict = dict;
25
+ char* const dataAfterDict = dict + dictSize;
26
+ char* const smallDict = dataAfterDict - smallDictSize;
27
+
28
+ FUZZ_ASSERT(dst);
29
+ FUZZ_ASSERT(dict);
30
+
31
+ /* Prepare the dictionary. The data doesn't matter for decompression. */
32
+ memset(dict, 0, dictSize);
33
+ memcpy(dataAfterDict, data, size);
34
+
35
+ /* Decompress using each possible dictionary configuration. */
36
+ /* No dictionary. */
37
+ LZ4_decompress_safe_usingDict((char const*)data, dst, size,
38
+ dstCapacity, NULL, 0);
39
+ /* Small external dictonary. */
40
+ LZ4_decompress_safe_usingDict((char const*)data, dst, size,
41
+ dstCapacity, smallDict, smallDictSize);
42
+ /* Large external dictionary. */
43
+ LZ4_decompress_safe_usingDict((char const*)data, dst, size,
44
+ dstCapacity, largeDict, largeDictSize);
45
+ /* Small prefix. */
46
+ LZ4_decompress_safe_usingDict((char const*)dataAfterDict, dst, size,
47
+ dstCapacity, smallDict, smallDictSize);
48
+ /* Large prefix. */
49
+ LZ4_decompress_safe_usingDict((char const*)data, dst, size,
50
+ dstCapacity, largeDict, largeDictSize);
51
+ /* Partial decompression. */
52
+ LZ4_decompress_safe_partial((char const*)data, dst, size,
53
+ dstCapacity, dstCapacity);
54
+ free(dst);
55
+ free(dict);
56
+
57
+ return 0;
58
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Fuzz target interface.
3
+ * Fuzz targets have some common parameters passed as macros during compilation.
4
+ * Check the documentation for each individual fuzzer for more parameters.
5
+ *
6
+ * @param FUZZ_RNG_SEED_SIZE:
7
+ * The number of bytes of the source to look at when constructing a seed
8
+ * for the deterministic RNG. These bytes are discarded before passing
9
+ * the data to lz4 functions. Every fuzzer initializes the RNG exactly
10
+ * once before doing anything else, even if it is unused.
11
+ * Default: 4.
12
+ * @param LZ4_DEBUG:
13
+ * This is a parameter for the lz4 library. Defining `LZ4_DEBUG=1`
14
+ * enables assert() statements in the lz4 library. Higher levels enable
15
+ * logging, so aren't recommended. Defining `LZ4_DEBUG=1` is
16
+ * recommended.
17
+ * @param LZ4_FORCE_MEMORY_ACCESS:
18
+ * This flag controls how the zstd library accesses unaligned memory.
19
+ * It can be undefined, or 0 through 2. If it is undefined, it selects
20
+ * the method to use based on the compiler. If testing with UBSAN set
21
+ * MEM_FORCE_MEMORY_ACCESS=0 to use the standard compliant method.
22
+ * @param FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
23
+ * This is the canonical flag to enable deterministic builds for fuzzing.
24
+ * Changes to zstd for fuzzing are gated behind this define.
25
+ * It is recommended to define this when building zstd for fuzzing.
26
+ */
27
+
28
+ #ifndef FUZZ_H
29
+ #define FUZZ_H
30
+
31
+ #ifndef FUZZ_RNG_SEED_SIZE
32
+ # define FUZZ_RNG_SEED_SIZE 4
33
+ #endif
34
+
35
+ #include <stddef.h>
36
+ #include <stdint.h>
37
+
38
+ #ifdef __cplusplus
39
+ extern "C" {
40
+ #endif
41
+
42
+ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size);
43
+
44
+ #ifdef __cplusplus
45
+ }
46
+ #endif
47
+
48
+ #endif
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ */
9
+
10
+ /**
11
+ * Helper functions for fuzzing.
12
+ */
13
+
14
+ #ifndef FUZZ_HELPERS_H
15
+ #define FUZZ_HELPERS_H
16
+
17
+ #include "fuzz.h"
18
+ #include "xxhash.h"
19
+ #include <stdint.h>
20
+ #include <stdio.h>
21
+ #include <stdlib.h>
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ #define LZ4_COMMONDEFS_ONLY
28
+ #ifndef LZ4_SRC_INCLUDED
29
+ #include "lz4.c" /* LZ4_count, constants, mem */
30
+ #endif
31
+
32
+ #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
33
+ #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
34
+
35
+ #define FUZZ_QUOTE_IMPL(str) #str
36
+ #define FUZZ_QUOTE(str) FUZZ_QUOTE_IMPL(str)
37
+
38
+ /**
39
+ * Asserts for fuzzing that are always enabled.
40
+ */
41
+ #define FUZZ_ASSERT_MSG(cond, msg) \
42
+ ((cond) ? (void)0 \
43
+ : (fprintf(stderr, "%s: %u: Assertion: `%s' failed. %s\n", __FILE__, \
44
+ __LINE__, FUZZ_QUOTE(cond), (msg)), \
45
+ abort()))
46
+ #define FUZZ_ASSERT(cond) FUZZ_ASSERT_MSG((cond), "");
47
+
48
+ #if defined(__GNUC__)
49
+ #define FUZZ_STATIC static __inline __attribute__((unused))
50
+ #elif defined(__cplusplus) || \
51
+ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
52
+ #define FUZZ_STATIC static inline
53
+ #elif defined(_MSC_VER)
54
+ #define FUZZ_STATIC static __inline
55
+ #else
56
+ #define FUZZ_STATIC static
57
+ #endif
58
+
59
+ /**
60
+ * Deterministically constructs a seed based on the fuzz input.
61
+ * Consumes up to the first FUZZ_RNG_SEED_SIZE bytes of the input.
62
+ */
63
+ FUZZ_STATIC uint32_t FUZZ_seed(uint8_t const **src, size_t* size) {
64
+ uint8_t const *data = *src;
65
+ size_t const toHash = MIN(FUZZ_RNG_SEED_SIZE, *size);
66
+ *size -= toHash;
67
+ *src += toHash;
68
+ return XXH32(data, toHash, 0);
69
+ }
70
+
71
+ #define FUZZ_rotl32(x, r) (((x) << (r)) | ((x) >> (32 - (r))))
72
+
73
+ FUZZ_STATIC uint32_t FUZZ_rand(uint32_t *state) {
74
+ static const uint32_t prime1 = 2654435761U;
75
+ static const uint32_t prime2 = 2246822519U;
76
+ uint32_t rand32 = *state;
77
+ rand32 *= prime1;
78
+ rand32 += prime2;
79
+ rand32 = FUZZ_rotl32(rand32, 13);
80
+ *state = rand32;
81
+ return rand32 >> 5;
82
+ }
83
+
84
+ /* Returns a random numer in the range [min, max]. */
85
+ FUZZ_STATIC uint32_t FUZZ_rand32(uint32_t *state, uint32_t min, uint32_t max) {
86
+ uint32_t random = FUZZ_rand(state);
87
+ return min + (random % (max - min + 1));
88
+ }
89
+
90
+ #ifdef __cplusplus
91
+ }
92
+ #endif
93
+
94
+ #endif