From 206832f6e815bbba4e5837eba98f56f97bc26275 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 10 Oct 2026 10:32:56 +0530 Subject: [PATCH] fuzz: ops_sequence and corrupt_file targets that check results (#387) ops_sequence decodes up to 32 storage operations (transact, retract, write transaction, checkpoint, reopen, crash) and compares the database with the reference model after each one. The model-based test's driver and checks move into tests/reference_model so the test and the target share one oracle; Checks::One reads one input-chosen shape per step. corrupt_file flips bytes and truncates a three-checkpoint file without fixing checksums: every query must fail or return the answers of the last generation or the one before it, all from the same one. A file cut to under one page opens as a new empty database (#506); skipped until that is fixed. Refs #387 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012wXxZguv7PgKQjMMH4yJ5h --- CHANGELOG.md | 1 + ROADMAP.md | 2 +- fuzz/Cargo.toml | 15 + .../corrupt_file/seed_flip_free_list.bin | Bin 0 -> 10 bytes .../corrupt_file/seed_flip_internal.bin | Bin 0 -> 10 bytes fuzz/corpus/corrupt_file/seed_flip_leaf.bin | Bin 0 -> 10 bytes fuzz/corpus/corrupt_file/seed_flip_meta_a.bin | Bin 0 -> 10 bytes fuzz/corpus/corrupt_file/seed_flip_meta_b.bin | Bin 0 -> 10 bytes .../seed_flip_meta_b_read_only.bin | Bin 0 -> 10 bytes fuzz/corpus/corrupt_file/seed_flip_value.bin | Bin 0 -> 10 bytes fuzz/corpus/corrupt_file/seed_no_edits.bin | Bin 0 -> 5 bytes .../corrupt_file/seed_no_edits_read_only.bin | Bin 0 -> 5 bytes .../corrupt_file/seed_truncate_last_page.bin | Bin 0 -> 5 bytes .../seed_reopen_checkpoint_crash_write_tx.bin | 1 + .../seed_retract_checkpoint_reopen_crash.bin | Bin 0 -> 29 bytes .../seed_transact_reopen_write_tx.bin | 1 + .../seed_write_tx_commit_rollback.bin | 1 + fuzz/fuzz_targets/corrupt_file.rs | 202 +++++++++ fuzz/fuzz_targets/ops_sequence.rs | 206 +++++++++ tests/model_based_test.rs | 388 +---------------- tests/reference_model/mod.rs | 409 +++++++++++++++++- 21 files changed, 849 insertions(+), 377 deletions(-) create mode 100644 fuzz/corpus/corrupt_file/seed_flip_free_list.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_internal.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_leaf.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_meta_a.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_meta_b.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_meta_b_read_only.bin create mode 100644 fuzz/corpus/corrupt_file/seed_flip_value.bin create mode 100644 fuzz/corpus/corrupt_file/seed_no_edits.bin create mode 100644 fuzz/corpus/corrupt_file/seed_no_edits_read_only.bin create mode 100644 fuzz/corpus/corrupt_file/seed_truncate_last_page.bin create mode 100644 fuzz/corpus/ops_sequence/seed_reopen_checkpoint_crash_write_tx.bin create mode 100644 fuzz/corpus/ops_sequence/seed_retract_checkpoint_reopen_crash.bin create mode 100644 fuzz/corpus/ops_sequence/seed_transact_reopen_write_tx.bin create mode 100644 fuzz/corpus/ops_sequence/seed_write_tx_commit_rollback.bin create mode 100644 fuzz/fuzz_targets/corrupt_file.rs create mode 100644 fuzz/fuzz_targets/ops_sequence.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ae0c6403..793748080a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Model-based storage test (#385).** `tests/model_based_test.rs` runs random sequences of `transact` (multi-valued batches, transaction- and fact-level valid-time windows, a triple repeated with another window), `retract`, write transactions (committed or rolled back, retracting their own assertions), checkpoints, reopens (default, a 4-page cache, auto-checkpoint every 2 writes) and simulated crashes (a copy of the `.graph` file and WAL taken while the handle is open, so the WAL is replayed) against a file in a temp dir. After every step, `current_tx_count`, `verify`, full rows with windows and tx counts, and entity-, entity+attribute-, attribute-, attribute+value-, value-bound and full-scan queries, under `:as-of N` and `:valid-at T`, must match a plain reference model (one valid-time window per triple, #435; API-011 for two windows of one triple in one statement and API-019 for an empty or inverted window, from `execute` and `tx.execute`, #436; the last statement that writes a triple decides it at commit, #477). Reads inside a write transaction are checked against what its commit will hold. Normal CI runs 24 cases; the nightly property-test workflow runs 30,000. - **SIGKILL crash test checks committed data (#384).** `tests/crash_kill_test.rs` used to check only that the file reopened and one attribute query ran, so it missed #370 and could not reach #371. The child now runs a seeded workload (multi-valued batches, batched retracts, re-assertions) and logs each transaction after `execute` returns; it checkpoints after every transaction, every third, never (WAL replay), automatically every 2 writes, or every third with `SyncMode::Normal`. After a `SIGKILL` at a random point, the reopened file must hold exactly the model after the last logged transaction or the one in flight, through a full scan, attribute (AEVT), attribute+value (AVET) and entity-bound (EAVT) queries and `:as-of`, with `verify` clean. The checks run again after a second reopen and after a checkpoint plus reopen. Per-PR CI runs 5 rounds (one per mode); the nightly crash-kill workflow runs 100 per OS. `MINIGRAF_CRASH_KILL_SEED` replays a failure. - **Fuzzing reaches the v8 decoders, and the corpus is kept between runs (#387, #375).** On `v3`, the `btree_page` and `fact_page` targets still wrote the pre-release single-header layout and stopped at `STG-032` on every input, and `file_header` rarely got past the meta CRC. The page targets now start from a real v8 file built through the public API (rewritten with `LogWriter` at fixed tx times so its bytes are the same in every process). They overwrite one page with the input and recompute that page's checksum. `btree_page` fuzzes any leaf or internal node of the five trees, `file_header` fuzzes either meta slot (with or without a matching CRC, with or without the other slot), and `fact_page` fuzzes the fact page of a v7 golden file through migration and the read-only load. Each run executes one input-chosen probe query or `verify()`. The nightly fuzz workflow now runs every target in its own parallel job, on `main` and `v3` on alternating crons, and keeps each target's corpus in the Actions cache. A new weekly workflow (`fuzz-corpus.yml`) minimizes the cached corpus with `cargo fuzz cmin`, keeps every committed `seed_*` file, and proposes the result as a pull request. +- **Two fuzz targets check results, not just crashes (#387).** `ops_sequence` decodes the input into up to 32 storage operations (transact, retract, a write transaction that commits or rolls back, checkpoint, reopen, and a crash that opens a copy of the file and WAL) and, after each one, compares the full rows now and at an input-chosen `:as-of`, plus one input-chosen query shape, with the reference model of the model-based test. It uses that test's driver and checks, now in `tests/reference_model`, so the proptest test and the fuzzer share one oracle. `corrupt_file` damages a file written over three checkpoints with up to 16 byte flips and an optional truncation, without fixing any checksum, and requires every query to fail or to return exactly the answers of the last checkpoint or the one before it, all from the same one. Its first run found that a file cut to under one page opens as a new, empty database (#506); the target skips those lengths until that is fixed. ### Known issues diff --git a/ROADMAP.md b/ROADMAP.md index 4e353541f2..3343805dd7 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -91,7 +91,7 @@ Scope — release-gate testing and documentation: - SIGKILL crash test that checks committed data through EAVT, AEVT and full scan (#384; done on `v3`: `tests/crash_kill_test.rs`, 100 rounds per OS nightly) - Model-based test of transact/retract/checkpoint/reopen (#385; done on `v3`: `tests/model_based_test.rs`, 30,000 cases nightly) - Wider property tests: file-backed, batched, retracts, temporal, joins (#386) -- Persistent fuzz corpus and an operation-sequence target (#387; corpus caching, weekly `cmin` and the v8 page targets done on `v3`; `ops_sequence` and `corrupt_file` targets next) +- Persistent fuzz corpus and an operation-sequence target (#387; done on `v3`: corpus caching, weekly `cmin`, the v8 page targets, and the `ops_sequence` and `corrupt_file` targets) - Fault injection across save/WAL/recovery (#390) - Long-running soak test at scale (#392) - Benchmarks at 100K–10M facts and a published performance envelope (#394) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 7eb259d8e6..bfc1d5535b 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -14,6 +14,9 @@ libfuzzer-sys = "0.4" minigraf = { path = ".." } tempfile = "3" crc32fast = "1" +# ops_sequence includes tests/reference_model, shared with the model-based test. +proptest = "1" +uuid = { version = "1.0", features = ["v5"] } [[bin]] name = "wal_entry" @@ -50,3 +53,15 @@ name = "datalog_eval" path = "fuzz_targets/datalog_eval.rs" test = false doc = false + +[[bin]] +name = "ops_sequence" +path = "fuzz_targets/ops_sequence.rs" +test = false +doc = false + +[[bin]] +name = "corrupt_file" +path = "fuzz_targets/corrupt_file.rs" +test = false +doc = false diff --git a/fuzz/corpus/corrupt_file/seed_flip_free_list.bin b/fuzz/corpus/corrupt_file/seed_flip_free_list.bin new file mode 100644 index 0000000000000000000000000000000000000000..7506521fa8108353733a0a43de2f788efd182aff GIT binary patch literal 10 PcmZQz00OxKj0}tb1Ec`q literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_internal.bin b/fuzz/corpus/corrupt_file/seed_flip_internal.bin new file mode 100644 index 0000000000000000000000000000000000000000..c8e41ad57a8c29623fb2ea0c348764118caa6ed6 GIT binary patch literal 10 PcmZQz00KD$1_nj|0U-cD literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_leaf.bin b/fuzz/corpus/corrupt_file/seed_flip_leaf.bin new file mode 100644 index 0000000000000000000000000000000000000000..1cea8b7308d31fb7002fbb78354f5b39bbc2fc40 GIT binary patch literal 10 PcmZQz0D=<^3=E6_1oHt3 literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_meta_a.bin b/fuzz/corpus/corrupt_file/seed_flip_meta_a.bin new file mode 100644 index 0000000000000000000000000000000000000000..45ff07ed9ebbfdccb038bbf06d691ced1e2adeb4 GIT binary patch literal 10 OcmZQz00IXfW&{8MO8`Ou literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_meta_b.bin b/fuzz/corpus/corrupt_file/seed_flip_meta_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..a716ac1c57d7fd5797f41a94af1267db34ecfa44 GIT binary patch literal 10 PcmZQz00IXA1_nj|0gC`q literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_meta_b_read_only.bin b/fuzz/corpus/corrupt_file/seed_flip_meta_b_read_only.bin new file mode 100644 index 0000000000000000000000000000000000000000..4e1c533653fdb41dc6b3cb884fec13138165c6e6 GIT binary patch literal 10 PcmZQ%00IXA1_nj|0hIt# literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_flip_value.bin b/fuzz/corpus/corrupt_file/seed_flip_value.bin new file mode 100644 index 0000000000000000000000000000000000000000..4e437ae3128b67485a2c8bb14778add0ee70f456 GIT binary patch literal 10 PcmZQz0D==67#SD=2DSlv literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_no_edits.bin b/fuzz/corpus/corrupt_file/seed_no_edits.bin new file mode 100644 index 0000000000000000000000000000000000000000..40b450dd9d8187f90cf9f13a80c3ded26f8ecfd7 GIT binary patch literal 5 KcmZQz00IC21pom6 literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_no_edits_read_only.bin b/fuzz/corpus/corrupt_file/seed_no_edits_read_only.bin new file mode 100644 index 0000000000000000000000000000000000000000..51d72fb29fa4ae1f23b57813624cfc74777a7abe GIT binary patch literal 5 KcmZQ%00IC23IGBC literal 0 HcmV?d00001 diff --git a/fuzz/corpus/corrupt_file/seed_truncate_last_page.bin b/fuzz/corpus/corrupt_file/seed_truncate_last_page.bin new file mode 100644 index 0000000000000000000000000000000000000000..359b7b82d37a0d3c24a6ee59b51831fe04045e9d GIT binary patch literal 5 McmZQ#IKapN00L0}!~g&Q literal 0 HcmV?d00001 diff --git a/fuzz/corpus/ops_sequence/seed_reopen_checkpoint_crash_write_tx.bin b/fuzz/corpus/ops_sequence/seed_reopen_checkpoint_crash_write_tx.bin new file mode 100644 index 0000000000..4c6967ed06 --- /dev/null +++ b/fuzz/corpus/ops_sequence/seed_reopen_checkpoint_crash_write_tx.bin @@ -0,0 +1 @@ +AAAAAAAA?vAAAAêA2AãAAAÃë=$Å \ No newline at end of file diff --git a/fuzz/corpus/ops_sequence/seed_retract_checkpoint_reopen_crash.bin b/fuzz/corpus/ops_sequence/seed_retract_checkpoint_reopen_crash.bin new file mode 100644 index 0000000000000000000000000000000000000000..30b248069e56ce4b74fcf8f2a163098a4b771836 GIT binary patch literal 29 lcmaFNc7^NTfAxR=|8p}iFf@rWb>@{EwffH_%J~2PKLFH24haAN literal 0 HcmV?d00001 diff --git a/fuzz/corpus/ops_sequence/seed_transact_reopen_write_tx.bin b/fuzz/corpus/ops_sequence/seed_transact_reopen_write_tx.bin new file mode 100644 index 0000000000..6b7b9e5ca5 --- /dev/null +++ b/fuzz/corpus/ops_sequence/seed_transact_reopen_write_tx.bin @@ -0,0 +1 @@ +ÝÝÝ?ÿZñ·È°£PWžBÀ[0ŒÉNéNq \ No newline at end of file diff --git a/fuzz/corpus/ops_sequence/seed_write_tx_commit_rollback.bin b/fuzz/corpus/ops_sequence/seed_write_tx_commit_rollback.bin new file mode 100644 index 0000000000..c11c729e1e --- /dev/null +++ b/fuzz/corpus/ops_sequence/seed_write_tx_commit_rollback.bin @@ -0,0 +1 @@ +<<>, +} + +struct Template { + bytes: Vec, + /// Answers after each of the three checkpoints, oldest first. + generations: Vec, +} + +fn rows(db: &Minigraf, query: &str) -> Option> { + match db.execute(query).ok()? { + QueryResult::QueryResults { results, .. } => { + let mut out: Vec = results.iter().map(|r| format!("{r:?}")).collect(); + out.sort(); + Some(out) + } + _ => None, + } +} + +fn answers(db: &Minigraf) -> Answers { + Answers { + tx_count: db.current_tx_count(), + rows: QUERIES + .iter() + .map(|q| rows(db, q).expect("template query")) + .collect(), + } +} + +fn template() -> &'static Template { + static T: OnceLock