//! Fuzzes the RTSP framer over a chunked byte stream. //! Asserts invariants, not only "no panic": never buffers past the cap, and the messages do not depend on how the stream is chunked (chunked vs one push). //! How to run: see the comment at the top of `fuzz/Cargo.toml`. #![no_main] use libfuzzer_sys::fuzz_target; use domistream::rtsp::{MAX_RTSP_MESSAGE_BYTES, RtspFramer}; fn frame(stream: &[u8], chunk: usize) -> Option>> { let mut f = RtspFramer::new(); let mut out = Vec::new(); for piece in stream.chunks(chunk) { f.push(piece).ok()?; assert!(f.buffered() <= MAX_RTSP_MESSAGE_BYTES); while let Some(m) = f.next_message().ok()? { let _ = domistream::rtsp::parse_response(&m); out.push(m); } } if let Some(last) = f.finish().ok()? { out.push(last); } Some(out) } fuzz_target!(|data: &[u8]| { // First byte picks the chunk size, so libFuzzer explores message boundaries across pushes. let Some((&chunk, rest)) = data.split_first() else { return }; let chunked = frame(rest, usize::from(chunk).max(1)); let whole = frame(rest, rest.len().max(1)); if let (Some(a), Some(b)) = (&chunked, &whole) { assert_eq!(a, b, "framing depends on chunking"); assert!(a.iter().map(Vec::len).sum::() <= rest.len()); } });