test: add deterministic parser fuzzing
This commit is contained in:
1 parent
7756bd9f60
commit
52ccd3e001
5 files changed
+94
-1
No files matched your search
@@ -304,6 +304,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
|
||||
- **Wave 105 (Sanitizer Groundwork)**: an ASan+UBSan build (`build/asan`) runs `vbs_core_tests` 7/7 clean with leak detection. It exposed a real VoidLibrary bug - `Argparse::option_default` use-after-free when the default aliases the output - filed as [Void/Library#62](https://git.faumaray.com/Void/Library/issues/62) and worked around by de-aliasing the `gc`/`clean` call sites. Full-binary ASan testing is limited because descriptor compilation does not inherit sanitizer flags (recorded as tooling work).
|
||||
|
||||
- **Wave 106 (Deterministic Parser Fuzzing)**: `CoreEngineTests.fuzz_mutated_inputs_never_crash_parsers` mutates TOML, JSON, lockfile and tar seeds (bit flips, truncation, overwrite runs, junk insertion; fixed xorshift seed, 200 iterations) and feeds them to `load_dependencies_toml`, `Void::Json::Strict::parse`, `parse_lockfile` and `extract_safe_tar`, with seed sanity checks guarding against a vacuous fuzz. Clean in the normal build and under ASan+UBSan with leak detection.
|
||||
|
||||
## Remaining future scope
|
||||
|
||||
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
||||
|
||||
@@ -109,4 +109,5 @@ Base HEAD: `fe0d1a6`
|
||||
| Wave 103 (JUnit & test timeout) | `vbs test --junit FILE --test-timeout SECONDS` with aggregated JUnit XML | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; JUnit assertions and CLI contract pass, full CTest 8/8) | `src/Main.cpp`, `tests/{FullV1Tests,CliContracts}.cpp/cmake`, docs |
|
||||
| Wave 104 (Competitor benchmark harness) | `benchmarks/compare.sh` timing VBS vs CMake/Ninja vs Meson; baseline recorded | COMPLETE & VERIFIED (baseline observed; VBS 2578/209 ms vs CMake 98/9 ms on a 20-source fixture) | `benchmarks/compare.sh`, `docs/roadmap/22-superiority-and-gaps.md`, docs |
|
||||
| Wave 105 (Sanitizer groundwork) | ASan+UBSan build runs core tests clean; found and filed Void/Library#62 (Argparse aliasing UAF) with a de-aliasing workaround | COMPLETE & VERIFIED (core 7/7 under ASan; normal CTest 8/8) | `src/Main.cpp`, `docs/agent-workflow/VERIFICATION.md`, Void/Library#62 |
|
||||
| Wave 106 (Parser fuzzing) | Deterministic mutation fuzz test over TOML/JSON/lockfile/tar parsers with seed sanity checks; ASan-clean | COMPLETE & VERIFIED (normal build and ASan+UBSan) | `tests/CoreEngineTests.cpp`, docs |
|
||||
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
||||
@@ -1496,6 +1496,22 @@ ASAN_OPTIONS=detect_leaks=1 build/asan/bin/vbs_core_tests --no-color
|
||||
recorded as tooling work (propagate sanitizer flags to descriptor compilation), not a code bug.
|
||||
- Normal build CTest after the fix: **8 / 8 passed** in 278.59 s.
|
||||
|
||||
## Deterministic Parser Fuzzing (GCC 16.2, pin `0002e74`)
|
||||
|
||||
```sh
|
||||
dev cpp-gcc -c build/pinned/bin/vbs_core_tests --filter fuzz_mutated_inputs_never_crash_parsers --no-color
|
||||
dev cpp-gcc -c cmake --build build/asan --parallel 8
|
||||
ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 \
|
||||
dev cpp-gcc -c build/asan/bin/vbs_core_tests --filter fuzz_mutated_inputs_never_crash_parsers --no-color
|
||||
```
|
||||
|
||||
- 200 deterministic mutations (bit flips, truncation, overwrite runs, junk insertion) over TOML,
|
||||
JSON, lockfile and tar seeds fed to `load_dependencies_toml`, `Void::Json::Strict::parse`,
|
||||
`parse_lockfile`, and `extract_safe_tar`.
|
||||
- Normal build: **passed** (2.93 s). ASan+UBSan with leak detection: **passed** (3.05 s), no
|
||||
reports.
|
||||
- Seed sanity assertions ensure the unmutated inputs still parse.
|
||||
|
||||
## Limits and Unrun Checks
|
||||
|
||||
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
|
||||
|
||||
@@ -82,7 +82,7 @@ Concrete work this implies:
|
||||
5. Migration tooling (`vbs migrate`) and migrating VoidLibrary onto VBS (**trial verified**: VoidLibrary builds and tests with VBS in a separate clone; upstream #61 tracks the in-repo build description).
|
||||
6. Test-runner parity.
|
||||
7. Benchmarks against CMake/Meson/build2 on documented fixtures (including 10k-target scaling).
|
||||
8. CI on real runners, sanitizer jobs, parser fuzzing.
|
||||
8. CI on real runners, sanitizer jobs (**sanitizer build run done**), parser fuzzing (**deterministic mutation harness done**; coverage-guided libFuzzer still needs Clang).
|
||||
9. Remote execution workers.
|
||||
|
||||
## 6. Observed baseline (2026-12-05, x86_64, GCC 16.2, Debug, `benchmarks/compare.sh 20`)
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Package/Lockfile.hpp>
|
||||
#include <Void/Build/Package/Toml.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
@@ -15,6 +19,8 @@
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
#include <filesystem>
|
||||
#include <stop_token>
|
||||
#include <sys/stat.h>
|
||||
@@ -495,3 +501,71 @@ void apply(Void::Build::Target t);
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// === Fuzzing groundwork: deterministic mutation robustness over the parsers ===
|
||||
VOID_TEST(CoreEngineTests, fuzz_mutated_inputs_never_crash_parsers) {
|
||||
Void::FileSystem::TempDir tmp{"vbs_fuzz_"};
|
||||
|
||||
std::uint64_t rng = 0x9E3779B97F4A7C15ull;
|
||||
const auto next = [&]() {
|
||||
rng ^= rng << 13;
|
||||
rng ^= rng >> 7;
|
||||
rng ^= rng << 17;
|
||||
return rng;
|
||||
};
|
||||
const auto mutate = [&](std::string_view seed) {
|
||||
std::string out{seed};
|
||||
switch (next() % 4) {
|
||||
case 0: // flip one bit
|
||||
if (!out.empty()) {
|
||||
out[next() % out.size()] ^= static_cast<char>(1u << (next() % 8));
|
||||
}
|
||||
break;
|
||||
case 1: // truncate
|
||||
if (!out.empty()) {
|
||||
out.resize(next() % out.size());
|
||||
}
|
||||
break;
|
||||
case 2: // overwrite a run with a byte
|
||||
if (!out.empty()) {
|
||||
const std::size_t pos = next() % out.size();
|
||||
const std::size_t len = 1 + (next() % (out.size() - pos));
|
||||
out.replace(pos, len, len, static_cast<char>(next() % 256));
|
||||
}
|
||||
break;
|
||||
default: // insert junk
|
||||
out.insert(next() % (out.size() + 1), std::string(1 + (next() % 8),
|
||||
static_cast<char>(next() % 256)));
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
const std::string toml_seed =
|
||||
"[dependencies.demo]\npath = \"vendor/demo\"\nbuilder = \"native\"\n";
|
||||
const std::string json_seed = "{\"a\":[1,true,\"x\"],\"b\":{\"c\":null}}";
|
||||
const std::string tar_seed = std::string(1024, '\0');
|
||||
const std::string lock_seed = Package::serialize_lockfile(Package::LockfileDocument{});
|
||||
|
||||
constexpr int kIterations = 200;
|
||||
for (int i = 0; i < kIterations; ++i) {
|
||||
const auto toml_text = mutate(toml_seed);
|
||||
const auto toml_path = tmp / std::format("f{}.toml", i);
|
||||
write_text_file(toml_path, toml_text);
|
||||
(void)Package::load_dependencies_toml(toml_path);
|
||||
|
||||
(void)Void::Json::Strict::parse(mutate(json_seed));
|
||||
(void)Package::parse_lockfile(mutate(lock_seed));
|
||||
|
||||
const auto tar_path = tmp / std::format("f{}.tar", i);
|
||||
write_text_file(tar_path, mutate(tar_seed));
|
||||
(void)Package::extract_safe_tar(tar_path, tmp / std::format("x{}", i));
|
||||
}
|
||||
|
||||
// The unmutated seeds must still parse (guards against a vacuous fuzz).
|
||||
const auto seed_toml = tmp / "seed.toml";
|
||||
write_text_file(seed_toml, toml_seed);
|
||||
Void::Testing::expect(Package::load_dependencies_toml(seed_toml).has_value());
|
||||
Void::Testing::expect(Void::Json::Strict::parse(json_seed).has_value());
|
||||
Void::Testing::expect(Package::parse_lockfile(lock_seed).has_value());
|
||||
}
|
||||
Reference in new issue
Block a user