extlz4 0.2.5 → 0.3.4
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.
- checksums.yaml +4 -4
- data/HISTORY.ja.md +16 -1
- data/README.md +49 -51
- data/Rakefile +22 -0
- data/bin/extlz4 +1 -1
- data/contrib/lz4/LICENSE +2 -1
- data/contrib/lz4/Makefile.inc +111 -0
- data/contrib/lz4/NEWS +97 -0
- data/contrib/lz4/README.md +41 -36
- data/contrib/lz4/build/README.md +55 -0
- data/contrib/lz4/build/VS2010/datagen/datagen.vcxproj +169 -0
- data/contrib/lz4/build/VS2010/frametest/frametest.vcxproj +176 -0
- data/contrib/lz4/build/VS2010/fullbench/fullbench.vcxproj +176 -0
- data/contrib/lz4/build/VS2010/fullbench-dll/fullbench-dll.vcxproj +180 -0
- data/contrib/lz4/build/VS2010/fuzzer/fuzzer.vcxproj +173 -0
- data/contrib/lz4/build/VS2010/liblz4/liblz4.vcxproj +175 -0
- data/contrib/lz4/build/VS2010/liblz4-dll/liblz4-dll.rc +51 -0
- data/contrib/lz4/build/VS2010/liblz4-dll/liblz4-dll.vcxproj +179 -0
- data/contrib/lz4/build/VS2010/lz4/lz4.rc +51 -0
- data/contrib/lz4/build/VS2010/lz4/lz4.vcxproj +189 -0
- data/contrib/lz4/build/VS2010/lz4.sln +98 -0
- data/contrib/lz4/build/VS2017/datagen/datagen.vcxproj +173 -0
- data/contrib/lz4/build/VS2017/frametest/frametest.vcxproj +180 -0
- data/contrib/lz4/build/VS2017/fullbench/fullbench.vcxproj +180 -0
- data/contrib/lz4/build/VS2017/fullbench-dll/fullbench-dll.vcxproj +184 -0
- data/contrib/lz4/build/VS2017/fuzzer/fuzzer.vcxproj +177 -0
- data/contrib/lz4/build/VS2017/liblz4/liblz4.vcxproj +179 -0
- data/contrib/lz4/build/VS2017/liblz4-dll/liblz4-dll.rc +51 -0
- data/contrib/lz4/build/VS2017/liblz4-dll/liblz4-dll.vcxproj +183 -0
- data/contrib/lz4/build/VS2017/lz4/lz4.rc +51 -0
- data/contrib/lz4/build/VS2017/lz4/lz4.vcxproj +175 -0
- data/contrib/lz4/build/VS2017/lz4.sln +103 -0
- data/contrib/lz4/build/VS2022/datagen/datagen.vcxproj +173 -0
- data/contrib/lz4/build/VS2022/frametest/frametest.vcxproj +180 -0
- data/contrib/lz4/build/VS2022/fullbench/fullbench.vcxproj +180 -0
- data/contrib/lz4/build/VS2022/fullbench-dll/fullbench-dll.vcxproj +184 -0
- data/contrib/lz4/build/VS2022/fuzzer/fuzzer.vcxproj +177 -0
- data/contrib/lz4/build/VS2022/liblz4/liblz4.vcxproj +179 -0
- data/contrib/lz4/build/VS2022/liblz4-dll/liblz4-dll.rc +51 -0
- data/contrib/lz4/build/VS2022/liblz4-dll/liblz4-dll.vcxproj +183 -0
- data/contrib/lz4/build/VS2022/lz4.sln +103 -0
- data/contrib/lz4/build/cmake/CMakeLists.txt +273 -0
- data/contrib/lz4/build/cmake/lz4Config.cmake.in +2 -0
- data/contrib/lz4/lib/LICENSE +1 -1
- data/contrib/lz4/lib/README.md +111 -15
- data/contrib/lz4/lib/liblz4-dll.rc.in +35 -0
- data/contrib/lz4/lib/liblz4.pc.in +3 -3
- data/contrib/lz4/lib/lz4.c +1891 -733
- data/contrib/lz4/lib/lz4.h +597 -234
- data/contrib/lz4/lib/lz4file.c +311 -0
- data/contrib/lz4/lib/lz4file.h +93 -0
- data/contrib/lz4/lib/lz4frame.c +896 -493
- data/contrib/lz4/lib/lz4frame.h +408 -107
- data/contrib/lz4/lib/lz4frame_static.h +5 -112
- data/contrib/lz4/lib/lz4hc.c +1039 -301
- data/contrib/lz4/lib/lz4hc.h +264 -123
- data/contrib/lz4/lib/xxhash.c +376 -240
- data/contrib/lz4/lib/xxhash.h +128 -93
- data/contrib/lz4/ossfuzz/Makefile +79 -0
- data/contrib/lz4/ossfuzz/compress_frame_fuzzer.c +48 -0
- data/contrib/lz4/ossfuzz/compress_fuzzer.c +58 -0
- data/contrib/lz4/ossfuzz/compress_hc_fuzzer.c +64 -0
- data/contrib/lz4/ossfuzz/decompress_frame_fuzzer.c +75 -0
- data/contrib/lz4/ossfuzz/decompress_fuzzer.c +78 -0
- data/contrib/lz4/ossfuzz/fuzz.h +48 -0
- data/contrib/lz4/ossfuzz/fuzz_data_producer.c +77 -0
- data/contrib/lz4/ossfuzz/fuzz_data_producer.h +36 -0
- data/contrib/lz4/ossfuzz/fuzz_helpers.h +95 -0
- data/contrib/lz4/ossfuzz/lz4_helpers.c +51 -0
- data/contrib/lz4/ossfuzz/lz4_helpers.h +13 -0
- data/contrib/lz4/ossfuzz/ossfuzz.sh +23 -0
- data/contrib/lz4/ossfuzz/round_trip_frame_fuzzer.c +43 -0
- data/contrib/lz4/ossfuzz/round_trip_frame_uncompressed_fuzzer.c +134 -0
- data/contrib/lz4/ossfuzz/round_trip_fuzzer.c +117 -0
- data/contrib/lz4/ossfuzz/round_trip_hc_fuzzer.c +44 -0
- data/contrib/lz4/ossfuzz/round_trip_stream_fuzzer.c +302 -0
- data/contrib/lz4/ossfuzz/standaloneengine.c +74 -0
- data/contrib/lz4/ossfuzz/travisoss.sh +26 -0
- data/ext/blockapi.c +13 -48
- data/ext/extlz4.c +2 -0
- data/ext/extlz4.h +17 -0
- data/ext/frameapi.c +3 -14
- data/ext/hashargs.c +9 -3
- data/ext/hashargs.h +1 -1
- data/ext/lz4_amalgam.c +0 -23
- data/gemstub.rb +5 -16
- data/lib/extlz4/oldstream.rb +1 -1
- data/lib/extlz4.rb +51 -3
- data/test/common.rb +2 -2
- metadata +84 -16
- data/contrib/lz4/circle.yml +0 -38
- data/contrib/lz4/lib/lz4opt.h +0 -356
- data/lib/extlz4/version.rb +0 -3
data/contrib/lz4/lib/xxhash.h
CHANGED
@@ -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-
|
61
|
-
It offers much better speed, but for 64-
|
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
|
-
*
|
87
|
-
*
|
88
|
-
*
|
89
|
-
*
|
90
|
-
* #
|
91
|
-
*
|
92
|
-
*
|
93
|
-
|
94
|
-
|
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
|
-
|
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
|
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-
|
160
|
+
* 32-bit hash
|
159
161
|
************************************************************************/
|
160
|
-
typedef unsigned int
|
162
|
+
typedef unsigned int XXH32_hash_t;
|
161
163
|
|
162
164
|
/*! XXH32() :
|
163
|
-
Calculate the 32-
|
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
|
-
|
181
|
-
Note that, for small input, they are slower than single-call functions, due to state management.
|
182
|
-
For small
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
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
|
-
*
|
209
|
-
*
|
210
|
-
*
|
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-
|
217
|
+
* 64-bit hash
|
217
218
|
************************************************************************/
|
218
219
|
typedef unsigned long long XXH64_hash_t;
|
219
220
|
|
220
221
|
/*! XXH64() :
|
221
|
-
Calculate the 64-
|
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-
|
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
|
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
|
-
|
250
|
-
Never use
|
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
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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,79 @@
|
|
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
|
+
round_trip_frame_uncompressed_fuzzer \
|
49
|
+
decompress_frame_fuzzer
|
50
|
+
|
51
|
+
.PHONY: all
|
52
|
+
all: $(FUZZERS)
|
53
|
+
|
54
|
+
# Include a rule to build the static library if calling this target
|
55
|
+
# directly.
|
56
|
+
$(LZ4DIR)/liblz4.a:
|
57
|
+
$(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
|
58
|
+
|
59
|
+
%.o: %.c
|
60
|
+
$(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
|
61
|
+
|
62
|
+
# Generic rule for generating fuzzers
|
63
|
+
ifeq ($(LIB_FUZZING_ENGINE),)
|
64
|
+
LIB_FUZZING_DEPS := standaloneengine.o
|
65
|
+
else
|
66
|
+
LIB_FUZZING_DEPS :=
|
67
|
+
endif
|
68
|
+
%_fuzzer: %_fuzzer.o lz4_helpers.o fuzz_data_producer.o $(LZ4DIR)/liblz4.a $(LIB_FUZZING_DEPS)
|
69
|
+
$(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
|
70
|
+
|
71
|
+
%_fuzzer_clean:
|
72
|
+
$(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o
|
73
|
+
|
74
|
+
.PHONY: clean
|
75
|
+
clean: compress_fuzzer_clean decompress_fuzzer_clean \
|
76
|
+
compress_frame_fuzzer_clean compress_hc_fuzzer_clean \
|
77
|
+
decompress_frame_fuzzer_clean round_trip_frame_fuzzer_clean \
|
78
|
+
round_trip_fuzzer_clean round_trip_hc_fuzzer_clean round_trip_stream_fuzzer_clean
|
79
|
+
$(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
|
+
}
|
@@ -0,0 +1,64 @@
|
|
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
|
+
#include "lz4hc.h"
|
16
|
+
|
17
|
+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
18
|
+
{
|
19
|
+
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
|
20
|
+
size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
|
21
|
+
size_t const levelSeed = FUZZ_dataProducer_retrieve32(producer);
|
22
|
+
size = FUZZ_dataProducer_remainingBytes(producer);
|
23
|
+
|
24
|
+
size_t const dstCapacity = FUZZ_getRange_from_uint32(dstCapacitySeed, 0, size);
|
25
|
+
int const level = FUZZ_getRange_from_uint32(levelSeed, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX);
|
26
|
+
|
27
|
+
char* const dst = (char*)malloc(dstCapacity);
|
28
|
+
char* const rt = (char*)malloc(size);
|
29
|
+
|
30
|
+
FUZZ_ASSERT(dst);
|
31
|
+
FUZZ_ASSERT(rt);
|
32
|
+
|
33
|
+
/* If compression succeeds it must round trip correctly. */
|
34
|
+
{
|
35
|
+
int const dstSize = LZ4_compress_HC((const char*)data, dst, size,
|
36
|
+
dstCapacity, level);
|
37
|
+
if (dstSize > 0) {
|
38
|
+
int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
|
39
|
+
FUZZ_ASSERT_MSG(rtSize == size, "Incorrect regenerated size");
|
40
|
+
FUZZ_ASSERT_MSG(!memcmp(data, rt, size), "Corruption!");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if (dstCapacity > 0) {
|
45
|
+
/* Compression succeeds and must round trip correctly. */
|
46
|
+
void* state = malloc(LZ4_sizeofStateHC());
|
47
|
+
FUZZ_ASSERT(state);
|
48
|
+
int compressedSize = size;
|
49
|
+
int const dstSize = LZ4_compress_HC_destSize(state, (const char*)data,
|
50
|
+
dst, &compressedSize,
|
51
|
+
dstCapacity, level);
|
52
|
+
FUZZ_ASSERT(dstSize > 0);
|
53
|
+
int const rtSize = LZ4_decompress_safe(dst, rt, dstSize, size);
|
54
|
+
FUZZ_ASSERT_MSG(rtSize == compressedSize, "Incorrect regenerated size");
|
55
|
+
FUZZ_ASSERT_MSG(!memcmp(data, rt, compressedSize), "Corruption!");
|
56
|
+
free(state);
|
57
|
+
}
|
58
|
+
|
59
|
+
free(dst);
|
60
|
+
free(rt);
|
61
|
+
FUZZ_dataProducer_free(producer);
|
62
|
+
|
63
|
+
return 0;
|
64
|
+
}
|
@@ -0,0 +1,75 @@
|
|
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 "fuzz_data_producer.h"
|
13
|
+
#include "lz4.h"
|
14
|
+
#define LZ4F_STATIC_LINKING_ONLY
|
15
|
+
#include "lz4frame.h"
|
16
|
+
#include "lz4_helpers.h"
|
17
|
+
|
18
|
+
static void decompress(LZ4F_dctx* dctx, void* dst, size_t dstCapacity,
|
19
|
+
const void* src, size_t srcSize,
|
20
|
+
const void* dict, size_t dictSize,
|
21
|
+
const LZ4F_decompressOptions_t* opts)
|
22
|
+
{
|
23
|
+
LZ4F_resetDecompressionContext(dctx);
|
24
|
+
if (dictSize == 0)
|
25
|
+
LZ4F_decompress(dctx, dst, &dstCapacity, src, &srcSize, opts);
|
26
|
+
else
|
27
|
+
LZ4F_decompress_usingDict(dctx, dst, &dstCapacity, src, &srcSize,
|
28
|
+
dict, dictSize, opts);
|
29
|
+
}
|
30
|
+
|
31
|
+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
32
|
+
{
|
33
|
+
FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(data, size);
|
34
|
+
size_t const dstCapacitySeed = FUZZ_dataProducer_retrieve32(producer);
|
35
|
+
size_t const dictSizeSeed = FUZZ_dataProducer_retrieve32(producer);
|
36
|
+
size = FUZZ_dataProducer_remainingBytes(producer);
|
37
|
+
|
38
|
+
size_t const dstCapacity = FUZZ_getRange_from_uint32(
|
39
|
+
dstCapacitySeed, 0, 4 * size);
|
40
|
+
size_t const largeDictSize = 64 * 1024;
|
41
|
+
size_t const dictSize = FUZZ_getRange_from_uint32(
|
42
|
+
dictSizeSeed, 0, largeDictSize);
|
43
|
+
|
44
|
+
char* const dst = (char*)malloc(dstCapacity);
|
45
|
+
char* const dict = (char*)malloc(dictSize);
|
46
|
+
LZ4F_decompressOptions_t opts;
|
47
|
+
LZ4F_dctx* dctx;
|
48
|
+
LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
|
49
|
+
|
50
|
+
FUZZ_ASSERT(dctx);
|
51
|
+
FUZZ_ASSERT(dst);
|
52
|
+
FUZZ_ASSERT(dict);
|
53
|
+
|
54
|
+
/* Prepare the dictionary. The data doesn't matter for decompression. */
|
55
|
+
memset(dict, 0, dictSize);
|
56
|
+
|
57
|
+
|
58
|
+
/* Decompress using multiple configurations. */
|
59
|
+
memset(&opts, 0, sizeof(opts));
|
60
|
+
opts.stableDst = 0;
|
61
|
+
decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
|
62
|
+
opts.stableDst = 1;
|
63
|
+
decompress(dctx, dst, dstCapacity, data, size, NULL, 0, &opts);
|
64
|
+
opts.stableDst = 0;
|
65
|
+
decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
|
66
|
+
opts.stableDst = 1;
|
67
|
+
decompress(dctx, dst, dstCapacity, data, size, dict, dictSize, &opts);
|
68
|
+
|
69
|
+
LZ4F_freeDecompressionContext(dctx);
|
70
|
+
free(dst);
|
71
|
+
free(dict);
|
72
|
+
FUZZ_dataProducer_free(producer);
|
73
|
+
|
74
|
+
return 0;
|
75
|
+
}
|