diff --git a/.gitignore b/.gitignore index 89ac8e22..0baaf01a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ dispatch tests/generate_unicode_test tests/sanity_test tests/sanity_test_vectors_generator +fuzzer # local conf .clang_complete diff --git a/Makefile b/Makefile index 6690f0a6..ddac8ea6 100644 --- a/Makefile +++ b/Makefile @@ -183,6 +183,7 @@ clean: ## remove all build artifacts $(Q)$(RM) xxhsum$(EXT) xxhsum32$(EXT) xxhsum_inlinedXXH$(EXT) dispatch$(EXT) $(Q)$(RM) xxhsum.wasm xxhsum.js xxhsum.html $(Q)$(RM) xxh32sum$(EXT) xxh64sum$(EXT) xxh128sum$(EXT) xxh3sum$(EXT) + $(Q)$(RM) fuzzer $(Q)$(RM) $(XXHSUM_SRC_DIR)/*.o $(XXHSUM_SRC_DIR)/*.obj $(MAKE) -C tests clean $(MAKE) -C tests/bench clean @@ -315,6 +316,13 @@ test-xxhsum-c: xxhsum echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1 @$(RM) .test.* +LIB_FUZZING_ENGINE?="-fsanitize=fuzzer" +CC_VERSION := $(shell $(CC) --version) +ifneq (,$(findstring clang,$(CC_VERSION))) +fuzzer: libxxhash.a fuzz/fuzzer.c + $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -I. -o fuzzer fuzz/fuzzer.c -L. -Wl,-Bstatic -lxxhash -Wl,-Bdynamic +endif + .PHONY: test-filename-escape test-filename-escape: $(MAKE) -C tests test_filename_escape diff --git a/fuzz/fuzzer.c b/fuzz/fuzzer.c new file mode 100644 index 00000000..731ba4d4 --- /dev/null +++ b/fuzz/fuzzer.c @@ -0,0 +1,11 @@ +#include +#include "xxhash.h" + + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + volatile XXH64_hash_t hash64 = XXH64(data, size, 0); + (void)hash64; + volatile XXH32_hash_t hash32 = XXH32(data, size, 0); + (void)hash32; + return 0; +}