extlz4 0.2.4.2 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +25 -0
  3. data/README.md +49 -41
  4. data/bin/extlz4 +1 -1
  5. data/contrib/lz4/INSTALL +1 -0
  6. data/contrib/lz4/Makefile.inc +87 -0
  7. data/contrib/lz4/NEWS +89 -0
  8. data/contrib/lz4/README.md +42 -36
  9. data/contrib/lz4/build/README.md +55 -0
  10. data/contrib/lz4/build/VS2010/datagen/datagen.vcxproj +169 -0
  11. data/contrib/lz4/build/VS2010/frametest/frametest.vcxproj +176 -0
  12. data/contrib/lz4/build/VS2010/fullbench-dll/fullbench-dll.vcxproj +180 -0
  13. data/contrib/lz4/build/VS2010/fullbench/fullbench.vcxproj +176 -0
  14. data/contrib/lz4/build/VS2010/fuzzer/fuzzer.vcxproj +173 -0
  15. data/contrib/lz4/build/VS2010/liblz4-dll/liblz4-dll.rc +51 -0
  16. data/contrib/lz4/build/VS2010/liblz4-dll/liblz4-dll.vcxproj +179 -0
  17. data/contrib/lz4/build/VS2010/liblz4/liblz4.vcxproj +175 -0
  18. data/contrib/lz4/build/VS2010/lz4.sln +98 -0
  19. data/contrib/lz4/build/VS2010/lz4/lz4.rc +51 -0
  20. data/contrib/lz4/build/VS2010/lz4/lz4.vcxproj +189 -0
  21. data/contrib/lz4/build/VS2017/datagen/datagen.vcxproj +173 -0
  22. data/contrib/lz4/build/VS2017/frametest/frametest.vcxproj +180 -0
  23. data/contrib/lz4/build/VS2017/fullbench-dll/fullbench-dll.vcxproj +184 -0
  24. data/contrib/lz4/build/VS2017/fullbench/fullbench.vcxproj +180 -0
  25. data/contrib/lz4/build/VS2017/fuzzer/fuzzer.vcxproj +177 -0
  26. data/contrib/lz4/build/VS2017/liblz4-dll/liblz4-dll.rc +51 -0
  27. data/contrib/lz4/build/VS2017/liblz4-dll/liblz4-dll.vcxproj +183 -0
  28. data/contrib/lz4/build/VS2017/liblz4/liblz4.vcxproj +179 -0
  29. data/contrib/lz4/build/VS2017/lz4.sln +103 -0
  30. data/contrib/lz4/build/VS2017/lz4/lz4.rc +51 -0
  31. data/contrib/lz4/build/VS2017/lz4/lz4.vcxproj +164 -0
  32. data/contrib/lz4/build/cmake/CMakeLists.txt +235 -0
  33. data/contrib/lz4/lib/README.md +98 -34
  34. data/contrib/lz4/lib/liblz4-dll.rc.in +35 -0
  35. data/contrib/lz4/lib/lz4.c +1698 -681
  36. data/contrib/lz4/lib/lz4.h +546 -235
  37. data/contrib/lz4/lib/lz4frame.c +608 -378
  38. data/contrib/lz4/lib/lz4frame.h +315 -83
  39. data/contrib/lz4/lib/lz4frame_static.h +4 -100
  40. data/contrib/lz4/lib/lz4hc.c +1090 -282
  41. data/contrib/lz4/lib/lz4hc.h +276 -141
  42. data/contrib/lz4/lib/xxhash.c +371 -235
  43. data/contrib/lz4/lib/xxhash.h +128 -93
  44. data/contrib/lz4/ossfuzz/Makefile +78 -0
  45. data/contrib/lz4/ossfuzz/compress_frame_fuzzer.c +48 -0
  46. data/contrib/lz4/ossfuzz/compress_fuzzer.c +58 -0
  47. data/contrib/lz4/ossfuzz/compress_hc_fuzzer.c +64 -0
  48. data/contrib/lz4/ossfuzz/decompress_frame_fuzzer.c +75 -0
  49. data/contrib/lz4/ossfuzz/decompress_fuzzer.c +62 -0
  50. data/contrib/lz4/ossfuzz/fuzz.h +48 -0
  51. data/contrib/lz4/ossfuzz/fuzz_data_producer.c +77 -0
  52. data/contrib/lz4/ossfuzz/fuzz_data_producer.h +36 -0
  53. data/contrib/lz4/ossfuzz/fuzz_helpers.h +94 -0
  54. data/contrib/lz4/ossfuzz/lz4_helpers.c +51 -0
  55. data/contrib/lz4/ossfuzz/lz4_helpers.h +13 -0
  56. data/contrib/lz4/ossfuzz/ossfuzz.sh +23 -0
  57. data/contrib/lz4/ossfuzz/round_trip_frame_fuzzer.c +43 -0
  58. data/contrib/lz4/ossfuzz/round_trip_fuzzer.c +57 -0
  59. data/contrib/lz4/ossfuzz/round_trip_hc_fuzzer.c +44 -0
  60. data/contrib/lz4/ossfuzz/round_trip_stream_fuzzer.c +302 -0
  61. data/contrib/lz4/ossfuzz/standaloneengine.c +74 -0
  62. data/contrib/lz4/ossfuzz/travisoss.sh +26 -0
  63. data/contrib/lz4/tmp +0 -0
  64. data/contrib/lz4/tmpsparse +0 -0
  65. data/ext/blockapi.c +5 -5
  66. data/ext/extlz4.c +2 -0
  67. data/ext/extlz4.h +5 -0
  68. data/ext/frameapi.c +1 -1
  69. data/ext/hashargs.c +2 -2
  70. data/ext/hashargs.h +1 -1
  71. data/ext/lz4_amalgam.c +0 -23
  72. data/gemstub.rb +5 -16
  73. data/lib/extlz4.rb +51 -3
  74. data/lib/extlz4/oldstream.rb +1 -1
  75. data/test/common.rb +2 -2
  76. metadata +73 -16
  77. data/contrib/lz4/circle.yml +0 -39
  78. data/contrib/lz4/lib/lz4opt.h +0 -366
  79. data/lib/extlz4/version.rb +0 -3
@@ -57,8 +57,8 @@ Q.Score is a measure of quality of the hash function.
57
57
  It depends on successfully passing SMHasher test set.
58
58
  10 is a perfect score.
59
59
 
60
- A 64-bits version, named XXH64, is available since r35.
61
- It offers much better speed, but for 64-bits applications only.
60
+ A 64-bit version, named XXH64, is available since r35.
61
+ It offers much better speed, but for 64-bit applications only.
62
62
  Name Speed on 64 bits Speed on 32 bits
63
63
  XXH64 13.8 GB/s 1.9 GB/s
64
64
  XXH32 6.8 GB/s 6.0 GB/s
@@ -80,18 +80,19 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
80
80
 
81
81
 
82
82
  /* ****************************
83
- * API modifier
84
- ******************************/
85
- /** XXH_PRIVATE_API
86
- * This is useful to include xxhash functions in `static` mode
87
- * in order to inline them, and remove their symbol from the public list.
88
- * Methodology :
89
- * #define XXH_PRIVATE_API
90
- * #include "xxhash.h"
91
- * `xxhash.c` is automatically included.
92
- * It's not useful to compile and link it as a separate module.
93
- */
94
- #ifdef XXH_PRIVATE_API
83
+ * API modifier
84
+ ******************************/
85
+ /** XXH_INLINE_ALL (and XXH_PRIVATE_API)
86
+ * This is useful to include xxhash functions in `static` mode
87
+ * in order to inline them, and remove their symbol from the public list.
88
+ * Inlining can offer dramatic performance improvement on small keys.
89
+ * Methodology :
90
+ * #define XXH_INLINE_ALL
91
+ * #include "xxhash.h"
92
+ * `xxhash.c` is automatically included.
93
+ * It's not useful to compile and link it as a separate module.
94
+ */
95
+ #if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
95
96
  # ifndef XXH_STATIC_LINKING_ONLY
96
97
  # define XXH_STATIC_LINKING_ONLY
97
98
  # endif
@@ -102,23 +103,24 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
102
103
  # elif defined(_MSC_VER)
103
104
  # define XXH_PUBLIC_API static __inline
104
105
  # else
105
- # define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */
106
+ /* this version may generate warnings for unused static functions */
107
+ # define XXH_PUBLIC_API static
106
108
  # endif
107
109
  #else
108
110
  # define XXH_PUBLIC_API /* do nothing */
109
- #endif /* XXH_PRIVATE_API */
110
-
111
- /*!XXH_NAMESPACE, aka Namespace Emulation :
112
-
113
- If you want to include _and expose_ xxHash functions from within your own library,
114
- but also want to avoid symbol collisions with other libraries which may also include xxHash,
115
-
116
- you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library
117
- with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values).
118
-
119
- Note that no change is required within the calling program as long as it includes `xxhash.h` :
120
- regular symbol name will be automatically translated by this header.
121
- */
111
+ #endif /* XXH_INLINE_ALL || XXH_PRIVATE_API */
112
+
113
+ /*! XXH_NAMESPACE, aka Namespace Emulation :
114
+ *
115
+ * If you want to include _and expose_ xxHash functions from within your own library,
116
+ * but also want to avoid symbol collisions with other libraries which may also include xxHash,
117
+ *
118
+ * you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library
119
+ * with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values).
120
+ *
121
+ * Note that no change is required within the calling program as long as it includes `xxhash.h` :
122
+ * regular symbol name will be automatically translated by this header.
123
+ */
122
124
  #ifdef XXH_NAMESPACE
123
125
  # define XXH_CAT(A,B) A##B
124
126
  # define XXH_NAME2(A,B) XXH_CAT(A,B)
@@ -149,18 +151,18 @@ regular symbol name will be automatically translated by this header.
149
151
  ***************************************/
150
152
  #define XXH_VERSION_MAJOR 0
151
153
  #define XXH_VERSION_MINOR 6
152
- #define XXH_VERSION_RELEASE 2
154
+ #define XXH_VERSION_RELEASE 5
153
155
  #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
154
156
  XXH_PUBLIC_API unsigned XXH_versionNumber (void);
155
157
 
156
158
 
157
159
  /*-**********************************************************************
158
- * 32-bits hash
160
+ * 32-bit hash
159
161
  ************************************************************************/
160
- typedef unsigned int XXH32_hash_t;
162
+ typedef unsigned int XXH32_hash_t;
161
163
 
162
164
  /*! XXH32() :
163
- Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
165
+ Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input".
164
166
  The memory between input & input+length must be valid (allocated and read-accessible).
165
167
  "seed" can be used to alter the result predictably.
166
168
  Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s */
@@ -177,26 +179,25 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void*
177
179
  XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr);
178
180
 
179
181
  /*
180
- These functions generate the xxHash of an input provided in multiple segments.
181
- Note that, for small input, they are slower than single-call functions, due to state management.
182
- For small input, prefer `XXH32()` and `XXH64()` .
183
-
184
- XXH state must first be allocated, using XXH*_createState() .
185
-
186
- Start a new hash by initializing state with a seed, using XXH*_reset().
187
-
188
- Then, feed the hash state by calling XXH*_update() as many times as necessary.
189
- Obviously, input must be allocated and read accessible.
190
- The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
191
-
192
- Finally, a hash value can be produced anytime, by using XXH*_digest().
193
- This function returns the nn-bits hash as an int or long long.
194
-
195
- It's still possible to continue inserting input into the hash state after a digest,
196
- and generate some new hashes later on, by calling again XXH*_digest().
197
-
198
- When done, free XXH state space if it was allocated dynamically.
199
- */
182
+ * Streaming functions generate the xxHash of an input provided in multiple segments.
183
+ * Note that, for small input, they are slower than single-call functions, due to state management.
184
+ * For small inputs, prefer `XXH32()` and `XXH64()`, which are better optimized.
185
+ *
186
+ * XXH state must first be allocated, using XXH*_createState() .
187
+ *
188
+ * Start a new hash by initializing state with a seed, using XXH*_reset().
189
+ *
190
+ * Then, feed the hash state by calling XXH*_update() as many times as necessary.
191
+ * The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
192
+ *
193
+ * Finally, a hash value can be produced anytime, by using XXH*_digest().
194
+ * This function returns the nn-bits hash as an int or long long.
195
+ *
196
+ * It's still possible to continue inserting input into the hash state after a digest,
197
+ * and generate some new hashes later on, by calling again XXH*_digest().
198
+ *
199
+ * When done, free XXH state space if it was allocated dynamically.
200
+ */
200
201
 
201
202
  /*====== Canonical representation ======*/
202
203
 
@@ -205,22 +206,22 @@ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t
205
206
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
206
207
 
207
208
  /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
208
- * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
209
- * These functions allow transformation of hash result into and from its canonical format.
210
- * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
211
- */
209
+ * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
210
+ * These functions allow transformation of hash result into and from its canonical format.
211
+ * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
212
+ */
212
213
 
213
214
 
214
215
  #ifndef XXH_NO_LONG_LONG
215
216
  /*-**********************************************************************
216
- * 64-bits hash
217
+ * 64-bit hash
217
218
  ************************************************************************/
218
219
  typedef unsigned long long XXH64_hash_t;
219
220
 
220
221
  /*! XXH64() :
221
- Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
222
+ Calculate the 64-bit hash of sequence of length "len" stored at memory address "input".
222
223
  "seed" can be used to alter the result predictably.
223
- This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
224
+ This function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark).
224
225
  */
225
226
  XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
226
227
 
@@ -241,48 +242,82 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
241
242
  #endif /* XXH_NO_LONG_LONG */
242
243
 
243
244
 
245
+
244
246
  #ifdef XXH_STATIC_LINKING_ONLY
245
247
 
246
248
  /* ================================================================================================
247
- This section contains definitions which are not guaranteed to remain stable.
249
+ This section contains declarations which are not guaranteed to remain stable.
248
250
  They may change in future versions, becoming incompatible with a different version of the library.
249
- They shall only be used with static linking.
250
- Never use these definitions in association with dynamic linking !
251
+ These declarations should only be used with static linking.
252
+ Never use them in association with dynamic linking !
251
253
  =================================================================================================== */
252
254
 
253
- /* These definitions are only meant to allow allocation of XXH state
254
- statically, on stack, or in a struct for example.
255
- Do not use members directly. */
256
-
257
- struct XXH32_state_s {
258
- unsigned total_len_32;
259
- unsigned large_len;
260
- unsigned v1;
261
- unsigned v2;
262
- unsigned v3;
263
- unsigned v4;
264
- unsigned mem32[4]; /* buffer defined as U32 for alignment */
265
- unsigned memsize;
266
- unsigned reserved; /* never read nor write, will be removed in a future version */
267
- }; /* typedef'd to XXH32_state_t */
268
-
269
- #ifndef XXH_NO_LONG_LONG
270
- struct XXH64_state_s {
271
- unsigned long long total_len;
272
- unsigned long long v1;
273
- unsigned long long v2;
274
- unsigned long long v3;
275
- unsigned long long v4;
276
- unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
277
- unsigned memsize;
278
- unsigned reserved[2]; /* never read nor write, will be removed in a future version */
279
- }; /* typedef'd to XXH64_state_t */
255
+ /* These definitions are only present to allow
256
+ * static allocation of XXH state, on stack or in a struct for example.
257
+ * Never **ever** use members directly. */
258
+
259
+ #if !defined (__VMS) \
260
+ && (defined (__cplusplus) \
261
+ || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
262
+ # include <stdint.h>
263
+
264
+ struct XXH32_state_s {
265
+ uint32_t total_len_32;
266
+ uint32_t large_len;
267
+ uint32_t v1;
268
+ uint32_t v2;
269
+ uint32_t v3;
270
+ uint32_t v4;
271
+ uint32_t mem32[4];
272
+ uint32_t memsize;
273
+ uint32_t reserved; /* never read nor write, might be removed in a future version */
274
+ }; /* typedef'd to XXH32_state_t */
275
+
276
+ struct XXH64_state_s {
277
+ uint64_t total_len;
278
+ uint64_t v1;
279
+ uint64_t v2;
280
+ uint64_t v3;
281
+ uint64_t v4;
282
+ uint64_t mem64[4];
283
+ uint32_t memsize;
284
+ uint32_t reserved[2]; /* never read nor write, might be removed in a future version */
285
+ }; /* typedef'd to XXH64_state_t */
286
+
287
+ # else
288
+
289
+ struct XXH32_state_s {
290
+ unsigned total_len_32;
291
+ unsigned large_len;
292
+ unsigned v1;
293
+ unsigned v2;
294
+ unsigned v3;
295
+ unsigned v4;
296
+ unsigned mem32[4];
297
+ unsigned memsize;
298
+ unsigned reserved; /* never read nor write, might be removed in a future version */
299
+ }; /* typedef'd to XXH32_state_t */
300
+
301
+ # ifndef XXH_NO_LONG_LONG /* remove 64-bit support */
302
+ struct XXH64_state_s {
303
+ unsigned long long total_len;
304
+ unsigned long long v1;
305
+ unsigned long long v2;
306
+ unsigned long long v3;
307
+ unsigned long long v4;
308
+ unsigned long long mem64[4];
309
+ unsigned memsize;
310
+ unsigned reserved[2]; /* never read nor write, might be removed in a future version */
311
+ }; /* typedef'd to XXH64_state_t */
312
+ # endif
313
+
314
+ # endif
315
+
316
+
317
+ #if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
318
+ # include "xxhash.c" /* include xxhash function bodies as `static`, for inlining */
280
319
  #endif
281
320
 
282
- # ifdef XXH_PRIVATE_API
283
- # include "xxhash.c" /* include xxhash function bodies as `static`, for inlining */
284
- # endif
285
-
286
321
  #endif /* XXH_STATIC_LINKING_ONLY */
287
322
 
288
323
 
@@ -0,0 +1,78 @@
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 ?=
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
+ .PHONY: all
51
+ all: $(FUZZERS)
52
+
53
+ # Include a rule to build the static library if calling this target
54
+ # directly.
55
+ $(LZ4DIR)/liblz4.a:
56
+ $(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
57
+
58
+ %.o: %.c
59
+ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
60
+
61
+ # Generic rule for generating fuzzers
62
+ ifeq ($(LIB_FUZZING_ENGINE),)
63
+ LIB_FUZZING_DEPS := standaloneengine.o
64
+ else
65
+ LIB_FUZZING_DEPS :=
66
+ endif
67
+ %_fuzzer: %_fuzzer.o lz4_helpers.o fuzz_data_producer.o $(LZ4DIR)/liblz4.a $(LIB_FUZZING_DEPS)
68
+ $(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
69
+
70
+ %_fuzzer_clean:
71
+ $(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o
72
+
73
+ .PHONY: clean
74
+ clean: compress_fuzzer_clean decompress_fuzzer_clean \
75
+ compress_frame_fuzzer_clean compress_hc_fuzzer_clean \
76
+ decompress_frame_fuzzer_clean round_trip_frame_fuzzer_clean \
77
+ round_trip_fuzzer_clean round_trip_hc_fuzzer_clean round_trip_stream_fuzzer_clean
78
+ $(MAKE) -C $(LZ4DIR) clean
@@ -0,0 +1,48 @@
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
+ #include "fuzz_data_producer.h"
17
+
18
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
19
+ {
20
+ FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
21
+ LZ4F_preferences_t const prefs = FUZZ_dataProducer_preferences(producer);
22
+ size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
23
+ size = FUZZ_dataProducer_remainingBytes(producer);
24
+
25
+ size_t const compressBound = LZ4F_compressFrameBound(size, &prefs);
26
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, compressBound);
27
+
28
+ char* const dst = (char*)malloc(dstCapacity);
29
+ char* const rt = (char*)malloc(size);
30
+
31
+ FUZZ_ASSERT(dst!=NULL);
32
+ FUZZ_ASSERT(rt!=NULL);
33
+
34
+ /* If compression succeeds it must round trip correctly. */
35
+ size_t const dstSize =
36
+ LZ4F_compressFrame(dst, dstCapacity, data, size, &prefs);
37
+ if (!LZ4F_isError(dstSize)) {
38
+ size_t const rtSize = FUZZ_decompressFrame(rt, size, dst, dstSize);
39
+ FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
40
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
41
+ }
42
+
43
+ free(dst);
44
+ free(rt);
45
+ FUZZ_dataProducer_free(producer);
46
+
47
+ return 0;
48
+ }
@@ -0,0 +1,58 @@
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 "fuzz_data_producer.h"
14
+ #include "lz4.h"
15
+
16
+ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17
+ {
18
+ FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
19
+ size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
20
+ size = FUZZ_dataProducer_remainingBytes(producer);
21
+
22
+ size_t const compressBound = LZ4_compressBound(size);
23
+ size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, compressBound);
24
+
25
+ char* const dst = (char*)malloc(dstCapacity);
26
+ char* const rt = (char*)malloc(size);
27
+
28
+ FUZZ_ASSERT(dst);
29
+ FUZZ_ASSERT(rt);
30
+
31
+ /* If compression succeeds it must round trip correctly. */
32
+ {
33
+ int const dstSize = LZ4_compress_default((const char*)data, dst,
34
+ size, dstCapacity);
35
+ if (dstSize > 0) {
36
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
37
+ FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
38
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
39
+ }
40
+ }
41
+
42
+ if (dstCapacity > 0) {
43
+ /* Compression succeeds and must round trip correctly. */
44
+ int compressedSize = size;
45
+ int const dstSize = LZ4_compress_destSize((const char*)data, dst,
46
+ &compressedSize, dstCapacity);
47
+ FUZZ_ASSERT(dstSize > 0);
48
+ int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
49
+ FUZZ_ASSERT_MSG(rtSize == compressedSize, "Incorrect regenerated size");
50
+ FUZZ_ASSERT_MSG(!memcmp(data, rt, compressedSize), "Corruption!");
51
+ }
52
+
53
+ free(dst);
54
+ free(rt);
55
+ FUZZ_dataProducer_free(producer);
56
+
57
+ return 0;
58
+ }