# - 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
%.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
--- /dev/null
+#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;
+}
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/