diff --git a/CMakeLists.txt b/CMakeLists.txt index 116b5cb..8e353cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,11 @@ if(HAS_LIB_FUZZER) target_link_libraries(fuzz PRIVATE simdjson) target_compile_options(fuzz PRIVATE -fsanitize=fuzzer ${TEST_FLAGS}) target_link_options(fuzz PRIVATE -fsanitize=fuzzer) +else() + add_executable(fuzz src/fuzz.cpp src/lib.cpp src/fuzz_driver.cpp) + target_include_directories(fuzz PRIVATE include) + target_link_libraries(fuzz PRIVATE simdjson) + target_compile_options(fuzz PRIVATE ${TEST_FLAGS}) endif() add_executable(validate src/validate.cpp) diff --git a/src/fuzz_driver.cpp b/src/fuzz_driver.cpp new file mode 100644 index 0000000..dd00727 --- /dev/null +++ b/src/fuzz_driver.cpp @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +int main(int argc, char **argv) { + auto doTest = [&]() { + for (int i = 1; i < argc; ++i) { + std::ifstream t(argv[i], std::ios::binary); + std::stringstream buffer; + buffer << t.rdbuf(); + auto str = buffer.str(); + LLVMFuzzerTestOneInput((const uint8_t *)str.data(), str.size()); + } + }; + doTest(); +}