mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-15 07:18:29 -04:00
Add afl-fuzz files
This commit is contained in:
parent
95fa3faba8
commit
3aecf2e057
12
tools/afl-fuzz/Makefile
Normal file
12
tools/afl-fuzz/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
SRC := $(wildcard */*.c)
|
||||
EXE := $(SRC:.c=)
|
||||
|
||||
CFLAGS := -O2 -s
|
||||
LDLIBS := -ldeflate
|
||||
LDFLAGS := -L../..
|
||||
CPPFLAGS := -I../..
|
||||
|
||||
all:$(EXE)
|
||||
|
||||
clean:
|
||||
rm -f $(EXE)
|
40
tools/afl-fuzz/deflate_compress/fuzz.c
Normal file
40
tools/afl-fuzz/deflate_compress/fuzz.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <assert.h>
|
||||
#include <libdeflate.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct deflate_decompressor *d;
|
||||
struct deflate_compressor *c;
|
||||
int ret;
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
struct stat stbuf;
|
||||
assert(fd >= 0);
|
||||
ret = fstat(fd, &stbuf);
|
||||
assert(!ret);
|
||||
|
||||
char in[stbuf.st_size];
|
||||
ret = read(fd, in, sizeof in);
|
||||
assert(ret == sizeof in);
|
||||
|
||||
c = deflate_alloc_compressor(6);
|
||||
d = deflate_alloc_decompressor();
|
||||
|
||||
char out[sizeof(in)];
|
||||
char checkarray[sizeof(in)];
|
||||
|
||||
size_t csize = deflate_compress(c, in,sizeof in, out, sizeof out);
|
||||
if (csize) {
|
||||
enum decompress_result res;
|
||||
res = deflate_decompress(d, out, csize, checkarray, sizeof in, NULL);
|
||||
assert(!res);
|
||||
assert(!memcmp(in, checkarray, sizeof in));
|
||||
}
|
||||
|
||||
deflate_free_compressor(c);
|
||||
deflate_free_decompressor(d);
|
||||
return 0;
|
||||
}
|
BIN
tools/afl-fuzz/deflate_compress/inputs/0
Normal file
BIN
tools/afl-fuzz/deflate_compress/inputs/0
Normal file
Binary file not shown.
28
tools/afl-fuzz/deflate_decompress/fuzz.c
Normal file
28
tools/afl-fuzz/deflate_decompress/fuzz.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <libdeflate.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct deflate_decompressor *d;
|
||||
int ret;
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
struct stat stbuf;
|
||||
assert(fd >= 0);
|
||||
ret = fstat(fd, &stbuf);
|
||||
assert(!ret);
|
||||
|
||||
char in[stbuf.st_size];
|
||||
ret = read(fd, in, sizeof in);
|
||||
assert(ret == sizeof in);
|
||||
|
||||
char out[sizeof(in) * 3];
|
||||
|
||||
d = deflate_alloc_decompressor();
|
||||
|
||||
deflate_decompress(d, in, sizeof in, out, sizeof out, NULL);
|
||||
deflate_free_decompressor(d);
|
||||
return 0;
|
||||
}
|
3
tools/afl-fuzz/deflate_decompress/inputs/0
Normal file
3
tools/afl-fuzz/deflate_decompress/inputs/0
Normal file
@ -0,0 +1,3 @@
|
||||
uЋ1
|
||||
В@EgЕBl5
|
||||
‚°VЕТи6j—«X{Ѓi=Џ•иl=ЂаОџ¬СlуЯьќ™?tнРзЅD
нЁт=ЇGС%ѕ©—2xФ‡7eрDЅУРs[ФРёUkЕчq№
|R/екµщл®°*FўMzљјv°•`РЗуrР1ЄуBЃч,lDuYj#0<ЕХћ2И0hЃEђ`№шI°ямWВ
|
28
tools/afl-fuzz/gzip_decompress/fuzz.c
Normal file
28
tools/afl-fuzz/gzip_decompress/fuzz.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <libdeflate.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct deflate_decompressor *d;
|
||||
int ret;
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
struct stat stbuf;
|
||||
assert(fd >= 0);
|
||||
ret = fstat(fd, &stbuf);
|
||||
assert(!ret);
|
||||
|
||||
char in[stbuf.st_size];
|
||||
ret = read(fd, in, sizeof in);
|
||||
assert(ret == sizeof in);
|
||||
|
||||
char out[sizeof(in) * 3];
|
||||
|
||||
d = deflate_alloc_decompressor();
|
||||
|
||||
gzip_decompress(d, in, sizeof in, out, sizeof out, NULL);
|
||||
deflate_free_decompressor(d);
|
||||
return 0;
|
||||
}
|
BIN
tools/afl-fuzz/gzip_decompress/inputs/0
Normal file
BIN
tools/afl-fuzz/gzip_decompress/inputs/0
Normal file
Binary file not shown.
14
tools/afl-fuzz/prepare_for_fuzz.sh
Executable file
14
tools/afl-fuzz/prepare_for_fuzz.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
make -C ../../ clean
|
||||
make clean
|
||||
AFL_HARDEN=1 make CC=afl-gcc -C ../../
|
||||
AFL_HARDEN=1 make CC=afl-gcc
|
||||
|
||||
for dir in $(find . -mindepth 1 -maxdepth 1 -type d); do
|
||||
rm -rf /tmp/$dir
|
||||
cp -va $dir /tmp/$dir
|
||||
mkdir -p /tmp/$dir/outputs
|
||||
done
|
28
tools/afl-fuzz/zlib_decompress/fuzz.c
Normal file
28
tools/afl-fuzz/zlib_decompress/fuzz.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <assert.h>
|
||||
#include <libdeflate.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct deflate_decompressor *d;
|
||||
int ret;
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
struct stat stbuf;
|
||||
assert(fd >= 0);
|
||||
ret = fstat(fd, &stbuf);
|
||||
assert(!ret);
|
||||
|
||||
char in[stbuf.st_size];
|
||||
ret = read(fd, in, sizeof in);
|
||||
assert(ret == sizeof in);
|
||||
|
||||
char out[sizeof(in) * 3];
|
||||
|
||||
d = deflate_alloc_decompressor();
|
||||
|
||||
zlib_decompress(d, in, sizeof in, out, sizeof out, NULL);
|
||||
deflate_free_decompressor(d);
|
||||
return 0;
|
||||
}
|
3
tools/afl-fuzz/zlib_decompress/inputs/0
Normal file
3
tools/afl-fuzz/zlib_decompress/inputs/0
Normal file
@ -0,0 +1,3 @@
|
||||
xњuЋ1
|
||||
В@EgЕBl5
|
||||
‚°VЕТи6j—«X{Ѓi=Џ•иl=ЂаОџ¬СlуЯьќ™?tнРзЅD
нЁт=ЇGС%ѕ©—2xФ‡7eрDЅУРs[ФРёUkЕчq№
|R/екµщл®°*FўMzљјv°•`РЗуrР1ЄуBЃч,lDuYj#0<ЕХћ2И0hЃEђ`№шI°ямWВђ-©
|
Loading…
x
Reference in New Issue
Block a user