fuzz: cargo-fuzz harness for the ratchet/qr/dispatch/file parsers #103
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_1265efb2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
OnionWire had no fuzz testing. The four parsers that eat untrusted peer input now have a cargo-fuzz harness, and all four survived a 60s/4-job run with zero crashes.
Targets (
fuzz/fuzz_targets/)ratchet_frameratchet::RatchetState::from_bytes,RatchetState::decryptratframe parser: prefix, version,MIN_FRAME_LEN,N/PNbounds, DH step, AEAD open. Every header field is attacker-controlled.qr_decodeqr::decodedispatch_classifydispatch::classifyRatchetarm is what routesratinto the parser. All 255 byte values in scope.file_decodefile::decodefilchunk headers: hex ids,idx/total, filename throughsafe_name.Each target asserts properties a panic-free decoder must hold, so it is not just "no signal": a rejected ratchet frame must leave the state byte-identical (
to_bytes()compared before/after), a decoded invite must be 32/32/*.onion-shaped, a decoded chunk must re-encode and decode back to the same header, andclassifymust be total and deterministic withratnever shadowed by the[a-z]{3}catch-all.Card naming note: the brief said
ratchet::decode()andRatchet::process_frame(). Those names do not exist insrc/ratchet.rs(whose parser is the privateFrame::parsebehindRatchetState::decrypt); the target calls the public entry point that reaches that shape instead.Scope
fuzz/directory only; nosrc/file touched, no rootCargo.tomldependency added (fuzz/Cargo.tomlcarries an empty[workspace]table, so it is a detached workspace:cargo metadataat the root still reports exactly['onionwire'], and a normal root build never compiles it).fuzz/Cargo.lockis committed on purpose, likecrates/onionwire-sdk's, so a fuzzer's dependency drift shows up in review.fuzz/seeds/<target>/is committed and copied into the gitignored working corpus by the script; a fixed crash gets folded back there so it regresses on every run.fuzz/corpus/is ignored because libFuzzer grows it locally (184 files after one 60s run) and that growth is noise, not source.Verification (real output)
fuzz/artifacts/*is empty for all four targets (a crash would leave acrash-<hash>reproducer there). Script exit code 0.Environment notes
rustup toolchain install nightly --profile minimalandcargo install cargo-fuzz, plus rustup'scargoahead of the distro one onPATH(a distrocargocannot resolve+nightly).onionwireitself (recursion_depth_exceeding_limit, future-incompatible, attached to the crate as a whole —TorClient::connect_with_prefsrecursion depth), on thesrc/outbox.rsboxed future. It is unrelated to this change and does not appear on the repo's pinned stable 1.98;src/is untouched here, so it is left alone.Not done (deliberately)
No CI job. The card scoped this to
fuzz/plusscripts/run-fuzz.sh, and a fuzz job in.forgejo/workflows/ci.ymlneeds a nightly runner plus a target-dir volume decision that belongs in its own card.Four pure parsers eat untrusted peer input and had no structured fuzzing: - ratchet_frame -> RatchetState::from_bytes + RatchetState::decrypt (the 'rat ' frame parser: prefix, version, length, N/PN bounds, DH step, AEAD open) - qr_decode -> qr::decode on pasted/scanned invite strings - dispatch_classify -> dispatch::classify on raw decrypted plaintext, including the 'rat ' -> Kind::Ratchet routing arm - file_decode -> file::decode on 'fil ' chunk frames No src/ change: every target calls the shipped public API. The fuzz crate is its own workspace (empty [workspace] table), so no root Cargo.toml dependency is added and cargo build/test at the root never compiles it. Seeds in fuzz/seeds/ are committed and copied into the gitignored working corpus by scripts/run-fuzz.sh; each target asserts properties a panic-free decode must hold (a rejected ratchet frame leaves the state byte-identical, a decoded invite is 32/32/onion-shaped, a decoded chunk re-encodes). Verified: cargo +nightly fuzz list -> 4 targets; scripts/run-fuzz.sh with FUZZ_SECS=60 FUZZ_JOBS=4 -> exit 0, oom/timeout/crash: 0/0/0 for all four, fuzz/artifacts/* empty.