test(fuzz): add a Clang/libFuzzer target for the header-only parsers
This commit is contained in:
1 parent
fd9e8673c0
commit
c2b80416a5
9 files changed
+64
-1
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Coverage-guided fuzz target for the standalone parsers (Clang/libFuzzer).
|
||||
// Build and run through fuzz/run.sh.
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Text/Semver.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) {
|
||||
const std::string_view input{reinterpret_cast<const char *>(data), size};
|
||||
(void)Void::Json::Strict::parse(input);
|
||||
// TOML/lockfile/tar are covered by the deterministic mutation harness
|
||||
// (CoreEngineTests.fuzz_mutated_inputs_never_crash_parsers): their implementations
|
||||
// are not header-only.
|
||||
(void)Void::Semver::parse_range(input);
|
||||
(void)Void::Semver::parse_strict(input);
|
||||
return 0;
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Coverage-guided fuzzing of the standalone parsers with Clang/libFuzzer.
|
||||
# Usage: VOID_INCLUDE_DIR=/path/to/VoidLibrary/include fuzz/run.sh [seconds] [extra libFuzzer args...]
|
||||
set -euo pipefail
|
||||
|
||||
root="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
seconds="${1:-60}"
|
||||
shift || true
|
||||
|
||||
: "${VOID_INCLUDE_DIR:?set VOID_INCLUDE_DIR to the VoidLibrary include directory}"
|
||||
|
||||
out="${FUZZ_OUT:-$root/build/fuzz}"
|
||||
corpus="$out/corpus"
|
||||
mkdir -p "$out" "$corpus"
|
||||
if [ -d "$root/fuzz/seeds" ]; then
|
||||
cp -n "$root/fuzz/seeds/"* "$corpus/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
clang++ -std=c++26 -O1 -g -fsanitize=fuzzer,address,undefined \
|
||||
-fno-omit-frame-pointer \
|
||||
-I"$root/include" -I"$root/recipes" -I"$VOID_INCLUDE_DIR" \
|
||||
"$root/fuzz/fuzz_parsers.cpp" -o "$out/fuzz_parsers"
|
||||
|
||||
exec "$out/fuzz_parsers" -max_total_time="$seconds" -max_len=65536 "$corpus" "$@"
|
||||
@@ -0,0 +1 @@
|
||||
{"a":[1,true,"x"],"b":{"c":null}}
|
||||
@@ -0,0 +1 @@
|
||||
{"schema_version":1,"revision_hash":"abc","contexts":{}}
|
||||
@@ -0,0 +1 @@
|
||||
^1.2.3
|
||||
Reference in new issue
Block a user