summaryrefslogtreecommitdiffstats
path: root/ossfuzz/compress_fuzzer.c
diff options
context:
space:
mode:
authorMax Dymond <cmeister2@gmail.com>2019-06-28 22:48:33 (GMT)
committerMax Dymond <cmeister2@gmail.com>2019-06-28 22:48:33 (GMT)
commit02b5b3c242fd4131983152f0dd422429e6702923 (patch)
treed070741a691775869a155706389e7bf1b38c9e1c /ossfuzz/compress_fuzzer.c
parent60d71dc20c5f9bb95e0b963ab6fb19212eb441a9 (diff)
downloadlz4-02b5b3c242fd4131983152f0dd422429e6702923.zip
lz4-02b5b3c242fd4131983152f0dd422429e6702923.tar.gz
lz4-02b5b3c242fd4131983152f0dd422429e6702923.tar.bz2
Move to using C rather than C++ for compilation
Diffstat (limited to 'ossfuzz/compress_fuzzer.c')
-rw-r--r--ossfuzz/compress_fuzzer.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/ossfuzz/compress_fuzzer.c b/ossfuzz/compress_fuzzer.c
new file mode 100644
index 0000000..28610ad
--- /dev/null
+++ b/ossfuzz/compress_fuzzer.c
@@ -0,0 +1,26 @@
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "lz4.h"
+
+#define CHECK(COND) if (!(COND)) { abort(); }
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ size_t const compressed_dest_size = LZ4_compressBound(size);
+ char *const dest_buffer = (char *)malloc(compressed_dest_size);
+
+ if (dest_buffer != NULL)
+ {
+ // Allocation succeeded, try compressing the incoming data.
+ int result = LZ4_compress_default((const char*)data,
+ dest_buffer,
+ size,
+ compressed_dest_size);
+ CHECK(result != 0);
+
+ free(dest_buffer);
+ }
+
+ return 0;
+}