Add a fuzz target
Every parser, decoder, protocol handler and state machine that takes
outside data has a cargo fuzz target (07 §3.4).
Findings stay in the corpus forever as regression tests.
Each fuzz project is a small crate of its own beside the crate it tests,
for example crates/orpheus-proto/fuzz/:
crates/orpheus-proto/fuzz/
├── Cargo.toml its own [workspace]; nightly only
├── src/lib.rs the target bodies: plain functions
└── fuzz_targets/
└── proto_records.rs libfuzzer_sys::fuzz_target!(|d| body(d))
-
Write the body in
src/lib.rsaspub fn name(data: &[u8]). It must not panic for any input and should check invariants withassert!(decoded length within bounds, a round trip that matches). -
Add the binary in
fuzz_targets/and a[[bin]]entry in the fuzz crate'sCargo.toml(withtest = false,doc = false). -
Replay on stable. The tested crate's
tests/fuzz_corpus.rsruns every committed input through the same bodies incargo test, so the corpus is checked without a nightly. Add the target there. -
Seeds. Committed corpus:
tests/fuzz-corpus/<target>/seed-*(rewritten bycargo xtask test fuzz-seeds), and a dictionarytests/fuzz-corpus/<target>.dictfor formats with magic words. -
Run it (needs a nightly and
cargo-fuzz):cd crates/orpheus-proto/fuzz cargo +nightly fuzz run proto_records ../../../tests/fuzz-corpus/proto_recordscargo xtask test fuzz-smokeruns every target for 60 s. -
A finding is minimised (
cargo fuzz tmin), fixed, and its input kept undertests/regress/<target>/with a name that says what it found. Record it in the findings table of STATUS. -
Coverage:
cargo xtask cover --fuzzshows what the corpus reaches.
The simulator's UI key-sequence target (sim/fuzz) works the same way;
its inputs are key scripts.