Write a simple decompress target as well

This commit is contained in:
Max Dymond 2019-06-28 22:19:27 +01:00
parent 88a7cfd728
commit 60d71dc20c
No known key found for this signature in database
GPG Key ID: 12A8D9E2219BD5FA
3 changed files with 34 additions and 5 deletions

View File

@ -21,7 +21,8 @@
# - LZ4 homepage : http://www.lz4.org
# - LZ4 source repository : https://github.com/lz4/lz4
# ##########################################################################
# lz4_fuzzer : OSS Fuzz test tool
# compress_fuzzer : OSS Fuzz test tool
# decompress_fuzzer : OSS Fuzz test tool
# ##########################################################################
LZ4DIR := ../lib
@ -44,8 +45,8 @@ $(LZ4DIR)/liblz4.a:
%.o: %.cc
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
.PHONY: compress_fuzzer
compress_fuzzer: compress_fuzzer.o $(LZ4DIR)/liblz4.a
# Generic rule for generating fuzzers
%_fuzzer: %_fuzzer.o $(LZ4DIR)/liblz4.a
# Compile the standalone code just in case. The OSS-Fuzz code might
# override the LIB_FUZZING_ENGINE value to "-fsanitize=fuzzer"
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) standaloneengine.cc -o standaloneengine.o

View File

@ -0,0 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "lz4.h"
#define CHECK(COND) if (!(COND)) { abort(); }
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
size_t const buffer_size = 10 * 1024 * 1024;
char *const dest_buffer = (char *)malloc(buffer_size);
if (dest_buffer != NULL)
{
// Allocation succeeded, try decompressing the incoming data.
int result = LZ4_decompress_safe((const char*)data,
dest_buffer,
size,
buffer_size);
// Ignore the result of decompression.
(void)result;
free(dest_buffer);
}
return 0;
}

View File

@ -16,8 +16,8 @@ echo "OUT: $OUT"
export MAKEFLAGS+="-j$(nproc)"
pushd ossfuzz
make V=1 compress_fuzzer
make V=1 compress_fuzzer decompress_fuzzer
popd
# Copy the fuzzers to the target directory.
cp -v ossfuzz/compress_fuzzer $OUT/
cp -v ossfuzz/compress_fuzzer ossfuzz/decompress_fuzzer $OUT/