-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: convert fuzzing scripts from afl-fuzz to libFuzzer
- Loading branch information
Showing
15 changed files
with
210 additions
and
294 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*/fuzz |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <assert.h> | ||
#include <libdeflate.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
/* Fuzz the DEFLATE compression and decompression round trip. */ | ||
int LLVMFuzzerTestOneInput(const uint8_t *in, size_t insize) | ||
{ | ||
int level; | ||
bool use_bound; | ||
struct libdeflate_compressor *c; | ||
struct libdeflate_decompressor *d; | ||
size_t csize_avail; | ||
uint8_t *cbuf; | ||
uint8_t *decompressed; | ||
size_t csize; | ||
enum libdeflate_result res; | ||
|
||
if (insize < 2) | ||
return 0; | ||
|
||
level = in[0] % 13; | ||
use_bound = in[1] % 2; | ||
in += 2; | ||
insize -= 2; | ||
|
||
c = libdeflate_alloc_compressor(level); | ||
d = libdeflate_alloc_decompressor(); | ||
|
||
csize_avail = use_bound ? libdeflate_deflate_compress_bound(c, insize) : | ||
insize; | ||
cbuf = malloc(csize_avail); | ||
decompressed = malloc(insize); | ||
|
||
csize = libdeflate_deflate_compress(c, in, insize, cbuf, csize_avail); | ||
if (csize != 0) { | ||
res = libdeflate_deflate_decompress(d, cbuf, csize, decompressed, | ||
insize, NULL); | ||
assert(res == LIBDEFLATE_SUCCESS); | ||
assert(memcmp(in, decompressed, insize) == 0); | ||
} else { | ||
assert(!use_bound); | ||
} | ||
|
||
libdeflate_free_compressor(c); | ||
libdeflate_free_decompressor(d); | ||
free(cbuf); | ||
free(decompressed); | ||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <libdeflate.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
/* Fuzz DEFLATE decompression. */ | ||
int LLVMFuzzerTestOneInput(const uint8_t *in, size_t insize) | ||
{ | ||
size_t outsize_avail = 3 * insize; | ||
uint8_t *out; | ||
struct libdeflate_decompressor *d; | ||
|
||
out = malloc(outsize_avail); | ||
|
||
d = libdeflate_alloc_decompressor(); | ||
libdeflate_deflate_decompress(d, in, insize, out, outsize_avail, NULL); | ||
libdeflate_free_decompressor(d); | ||
free(out); | ||
return 0; | ||
} |
Oops, something went wrong.