//! Fuzzes the host's ANNOUNCE parser (hostile client SDP). //! Asserts invariants, not only "no panic": an accepted payload is within every range and cap, and writing it back //! gives the same config. //! How to run: see the comment at the top of `fuzz/Cargo.toml`. #![no_main] use libfuzzer_sys::fuzz_target; use domistream::rtsp::server::{ MAX_ANNOUNCE_ATTRIBUTES, MAX_AUDIO_PACKET_DURATION_MS, MAX_BITRATE_KBPS, MAX_DIMENSION, MAX_FPS, MAX_PACKET_SIZE, MIN_PACKET_SIZE, StreamConfig, parse_announce, write_announce, }; fuzz_target!(|data: &[u8]| { let Ok(c) = parse_announce(data) else { return }; assert!((1..=MAX_DIMENSION).contains(&c.width) && (1..=MAX_DIMENSION).contains(&c.height)); assert!((1..=MAX_FPS).contains(&c.max_fps)); assert!((MIN_PACKET_SIZE..=MAX_PACKET_SIZE).contains(&c.packet_size)); assert!((1..=MAX_BITRATE_KBPS).contains(&c.bitrate_kbps)); assert!((1..=MAX_AUDIO_PACKET_DURATION_MS).contains(&c.audio_packet_duration_ms)); assert!((1..=8).contains(&c.surround.channels)); assert!(c.unknown_attributes as usize <= MAX_ANNOUNCE_ATTRIBUTES); let again = parse_announce(&write_announce(&c)).expect("what was accepted writes back"); assert_eq!(again, StreamConfig { unknown_attributes: 0, ..c }); });