//! Untrusted file-chunk bytes against the chunk decoder. //! //! A peer can send a `fil ` chunk at any time; `file::decode` header-parses it //! (hex transfer id, filename, hex sha256, `idx/total`, then the payload) before //! anything is written to disk. It must return `None` for every malformed //! chunk and never panic — including on absurd `idx`/`total` and on filenames //! that fail `safe_name`. #![no_main] use libfuzzer_sys::fuzz_target; use onionwire::file; fuzz_target!(|data: &[u8]| { if let Some(chunk) = file::decode(data) { // A chunk it accepted must survive an encode round-trip and decode // back to the same header, byte for byte. let re = file::encode(&chunk); let again = file::decode(&re).expect("encoded chunk must decode"); assert_eq!(again.xfer_id, chunk.xfer_id); assert_eq!(again.filename, chunk.filename); assert_eq!(again.sha256, chunk.sha256); assert_eq!(again.idx, chunk.idx); assert_eq!(again.total, chunk.total); assert_eq!(again.data, chunk.data); } });