onionwire/fuzz/fuzz_targets/qr_decode.rs
agent 518ef30232
All checks were successful
ci / test (pull_request) Successful in 4m51s
ci / sdk (pull_request) Successful in 58s
ci / fuzz (pull_request) Successful in 4m34s
Revert "ci: crash-test — inject panic in qr_decode to prove the fuzz job fails on a crash (REVERT BEFORE MERGE)"
This reverts commit b76bf46100.
2026-09-17 23:28:32 -04:00

28 lines
1.2 KiB
Rust

//! Untrusted invite strings against the QR/invite decoder.
//!
//! `qr::decode` takes a `&str` (the invite is pasted or scanned as text), so the
//! fuzzer input is read lossily as UTF-8. It must return `Err` for every
//! malformed invite — bad hex, wrong lengths, a non-v3 onion, a foreign
//! signature over a well-formed body — and never panic on any of them. The
//! `onionwire:v1:k=…` string is a QR code's payload, so the byte budget is
//! attacker-sized and the parse must stay bounded.
#![no_main]
use libfuzzer_sys::fuzz_target;
use onionwire::qr;
fuzz_target!(|data: &[u8]| {
let raw = String::from_utf8_lossy(data);
// The decoder is total over `&str`: no panic, no hang, no runaway allocation.
if let Ok(payload) = qr::decode(&raw) {
// Anything it accepted must be shaped as the payload promises; a decode
// that returns a malformed payload is as bad as a panic downstream.
assert_eq!(payload.pubkey.len(), 32);
assert_eq!(payload.signed_prekey.len(), 32);
assert!(payload.onion.ends_with(".onion"));
}
// Determinism: the same invite must decode to the same answer.
assert_eq!(qr::decode(&raw).is_ok(), qr::decode(&raw).is_ok());
});