DEBUGLEVEL?= 1
DEBUGFLAGS = -g -DLZ4_DEBUG=$(DEBUGLEVEL)
-CFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
-CXXFLAGS += -I$(LZ4DIR) $(DEBUGFLAGS) $(MOREFLAGS)
-CPPFLAGS += -DXXH_NAMESPACE=LZ4_
+LZ4_CFLAGS = $(CFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
+LZ4_CXXFLAGS = $(CXXFLAGS) $(DEBUGFLAGS) $(MOREFLAGS)
+LZ4_CPPFLAGS = $(CPPFLAGS) -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
include ../Makefile.inc
# Include a rule to build the static library if calling this target
# directly.
$(LZ4DIR)/liblz4.a:
- $(MAKE) -C $(LZ4DIR) CFLAGS="$(CFLAGS)" liblz4.a
+ $(MAKE) -C $(LZ4DIR) CFLAGS="$(LZ4_CFLAGS)" liblz4.a
%.o: %.c
- $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
+ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) $< -o $@
# 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"
- $(CC) -c $(CFLAGS) $(CPPFLAGS) standaloneengine.c -o standaloneengine.o
+ $(CC) -c $(LZ4_CFLAGS) $(LZ4_CPPFLAGS) standaloneengine.c -o standaloneengine.o
# Now compile the actual fuzzer.
- $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
+ $(CXX) $(LZ4_CXXFLAGS) $(LZ4_CPPFLAGS) $(LDFLAGS) $(LIB_FUZZING_ENGINE) $^ -o $@$(EXT)
%_fuzzer_clean:
$(RM) $*_fuzzer $*_fuzzer.o standaloneengine.o
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);
+ CHECK(dest_buffer != NULL);
- free(dest_buffer);
- }
+ // 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;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
+ // TODO: Size input buffer pseudo-randomly based on seed extracted from input
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);
+ CHECK(dest_buffer != NULL);
- // Ignore the result of decompression.
- (void)result;
+ // Allocation succeeded, try decompressing the incoming data.
+ int result = LZ4_decompress_safe((const char*)data,
+ dest_buffer,
+ size,
+ buffer_size);
- free(dest_buffer);
- }
+ // Ignore the result of decompression.
+ (void)result;
+
+ free(dest_buffer);
return 0;
}
+#ifndef TESTINPUT_H_INCLUDED
+#define TESTINPUT_H_INCLUDED
+
#include <inttypes.h>
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif