summaryrefslogtreecommitdiff
path: root/util/compress/libdeflate/scripts/afl-fuzz/zlib_decompress/fuzz.c
blob: 797343bbfb63e6eb25f244f46b27538e1623854d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <assert.h>
#include <libdeflate.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
	struct libdeflate_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 = libdeflate_alloc_decompressor();

	libdeflate_zlib_decompress(d, in, sizeof in, out, sizeof out, NULL);
	libdeflate_free_decompressor(d);
	return 0;
}