Skip to content

feat(fuzz): fuzz the FFI ingress boundary (input_entry_to_directive) - #1753

Merged
robcohen merged 2 commits into
mainfrom
feat/ffi-ingress-fuzz
Jul 10, 2026
Merged

robcohen merged 2 commits into
mainfrom
feat/ffi-ingress-fuzz

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

New cargo-fuzz crate + CI job for the FFI ingress boundary — the last hand-written validation surface with no fuzz coverage.

Why

input_entry_to_directive (behind the component's entry.create/createBatch) takes wire JSON from untrusted embedders and hand-validates it: date parsing, the account-name gate (#1739), cost-number arity, and the BookedCost per_unit × units == total invariant (try_new). The parser, query, and booking layers all have fuzz targets; this trust boundary had none.

How

  • Real wire path: bytes → serde_json → InputEntry → input_entry_to_directive, so serde's corners (deny_unknown_fields, defaults, tagged enums) are exercised exactly as embedders hit them.
  • Invariants beyond no-panic: (1) any Ok directive carries only accounts the canonical lexer predicate accepts — a bypass would readmit the un-round-trippable-account class the fix: one canonical account-name rule; validate FFI ingress; warn on bad name_* roots #1739 gate blocks; (2) conversion disposition is deterministic.
  • Committed seeds (fuzz/seeds/, one JSON per InputEntry variant plus the booked-pair and bad-account edges) double as by-example wire-format documentation; the CI job copies them into the corpus so cold caches start with structural coverage. corpus/ stays gitignored like the sibling fuzz crates.
  • fuzz.yml: fuzz-ffi-ingress job cloned from fuzz-booking (JSON needs max_len=4096), same crash-artifact policy; fuzz_input_entry added to the dispatch target choices.

Local shake

120 seconds under nightly libFuzzer: 9.65M executions, cov 6073, zero crashes, both invariants held.

🤖 Generated with Claude Code

The builder behind the component's entry.create/createBatch takes
wire JSON from untrusted embedders and hand-validates it — dates,
the account-name gate, cost-number arity, the BookedCost
per-unit x units == total invariant — and none of that validation
was fuzzed.

New cargo-fuzz crate for rustledger-ffi-wasi with one target:
arbitrary bytes driven through the REAL wire path
(serde_json -> InputEntry -> input_entry_to_directive), asserting
beyond no-panic that (1) any successfully converted directive
carries only accounts the canonical lexer predicate accepts — a
bypass would readmit the class #1739's gate blocks — and (2)
conversion disposition is deterministic.

Committed seeds (fuzz/seeds/, one JSON per InputEntry variant plus
booked-pair and bad-account edges) document the wire format by
example and are copied into the corpus before CI runs, so cold
caches start with structural coverage. fuzz.yml gains a
fuzz-ffi-ingress job cloned from fuzz-booking (max_len 4096 for
JSON) and the dispatch target list gains fuzz_input_entry.

Locally shaken: 9.65M executions over 120s, cov 6073, zero crashes,
both invariants held.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner July 10, 2026 16:38
Copilot AI review requested due to automatic review settings July 10, 2026 16:38
@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 31.6ms ± 0.5ms 23.4 MB
beancount 906.6ms ± 9.1ms 50.6 MB
Comparison 28.7x faster 2.2x less

vs main branch (2026-07-10)

Metric main this PR Change
Time 33.7ms 31.6ms -6.2% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds fuzz coverage for the rustledger-ffi-wasi JSON → InputEntry → input_entry_to_directive trust boundary, plus CI automation and a small seed corpus to bootstrap structural coverage. This strengthens robustness of the untrusted embedder ingress path, complementing existing fuzz targets for parser/query/booking.

Changes:

  • Introduces a new cargo-fuzz crate and fuzz_input_entry target that exercises the real wire path and asserts key invariants (account-name gate + conversion disposition determinism).
  • Adds a committed seed corpus (fuzz/seeds/fuzz_input_entry/) and a CI job (fuzz-ffi-ingress) that seeds the corpus on cold starts.
  • Extends the fuzz workflow dispatch options to include fuzz_input_entry.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rustledger-ffi-wasi/fuzz/fuzz_targets/fuzz_input_entry.rs New fuzz target for FFI ingress conversion + invariants.
crates/rustledger-ffi-wasi/fuzz/Cargo.toml New standalone fuzz crate configuration for cargo-fuzz.
crates/rustledger-ffi-wasi/fuzz/Cargo.lock Locked dependency graph for the fuzz crate.
crates/rustledger-ffi-wasi/fuzz/.gitignore Ignores fuzz build outputs/corpus/artifacts.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/open.json Seed JSON for InputEntry::Open.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/close.json Seed JSON for InputEntry::Close.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/balance.json Seed JSON for InputEntry::Balance.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/pad.json Seed JSON for InputEntry::Pad.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/note.json Seed JSON for InputEntry::Note.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/txn_per_unit.json Seed JSON for a transaction with per-unit cost.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/txn_compound.json Seed JSON for a transaction with compound cost.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/txn_booked_pair.json Seed JSON for a transaction with booked per-unit-from-total cost.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/inconsistent_pair.json Seed JSON for an intentionally inconsistent booked cost pair.
crates/rustledger-ffi-wasi/fuzz/seeds/fuzz_input_entry/bad_account.json Seed JSON for an invalid account-name edge.
.github/workflows/fuzz.yml Adds fuzz_input_entry dispatch option and a new CI job to run the new fuzzer and manage corpus/artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/fuzz.yml Resolved
Comment thread .github/workflows/fuzz.yml Resolved
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

- explicit 64 KiB input guard in the harness so resource usage is
  bounded regardless of runner flags;
- fuzz.yml pull_request paths gain crates/rustledger-ffi-wasi/** (the
  new job now runs where the boundary changes) and the workflow file
  itself;
- seeds for the six missing InputEntry variants (commodity, price,
  event, document, query, custom) so the "one per variant" comment is
  true — 16 seeds total, re-shaken 60s locally with zero findings.

Co-Authored-By: Claude Fable 5 <[email protected]>
@robcohen
robcohen merged commit 051d6f6 into main Jul 10, 2026
65 checks passed
@robcohen
robcohen deleted the feat/ffi-ingress-fuzz branch July 10, 2026 17:16
@robcohen robcohen mentioned this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants