Add afl-fuzz files

This commit is contained in:
Eric Biggers 2016-01-30 20:41:27 -06:00
parent 95fa3faba8
commit 3aecf2e057
10 changed files with 156 additions and 0 deletions

12
tools/afl-fuzz/Makefile Normal file
View 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)

View 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;
}

Binary file not shown.

View 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;
}

View 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РуBЃч,lDuYj#0<ЕХћ2И0hЃEђ`№шI°ямWВ

View 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;
}

Binary file not shown.

View 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

View 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;
}

View 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РуBЃч,lDuYj#0<ЕХћ2И0hЃEђ`№шI°ямWВђ-©