Skip to content

Commit

Permalink
Merge pull request #906 from silvergasp/dev
Browse files Browse the repository at this point in the history
Add fuzzing harness
  • Loading branch information
Cyan4973 authored Dec 28, 2023
2 parents 59b651e + 530e662 commit 29a366a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dispatch
tests/generate_unicode_test
tests/sanity_test
tests/sanity_test_vectors_generator
fuzzer

# local conf
.clang_complete
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions fuzz/fuzzer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdint.h>
#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;
}

0 comments on commit 29a366a

Please sign in to comment.