Write a simple decompress target as well
authorMax Dymond <cmeister2@gmail.com>
Fri, 28 Jun 2019 21:19:27 +0000 (22:19 +0100)
committerMax Dymond <cmeister2@gmail.com>
Fri, 28 Jun 2019 21:43:04 +0000 (22:43 +0100)
ossfuzz/Makefile
ossfuzz/decompress_fuzzer.cc [new file with mode: 0644]
ossfuzz/ossfuzz.sh

index 2a7e439..1e7679b 100644 (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
diff --git a/ossfuzz/decompress_fuzzer.cc b/ossfuzz/decompress_fuzzer.cc
new file mode 100644 (file)
index 0000000..594a5af
--- /dev/null
@@ -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;
+}
index 87bc213..a76b0d6 100755 (executable)
@@ -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/