//! Fuzzes SDP payloads, the host capabilities read from them, and `surround-params` values. //! Asserts invariants, not only "no panic": line and config caps hold; every Opus config obeys RFC 7845's rules. //! How to run: see the comment at the top of `fuzz/Cargo.toml`. #![no_main] use libfuzzer_sys::fuzz_target; use domistream::rtsp::sdp::{self, MAX_AUDIO_CHANNELS, MAX_OPUS_CONFIGS, MAX_SDP_LINES, OpusConfig}; fn valid(c: &OpusConfig) { assert!(c.channels >= 1 && usize::from(c.channels) <= MAX_AUDIO_CHANNELS); assert!(c.coupled_streams <= c.streams && c.streams >= 1); assert_eq!(c.mapping.len(), usize::from(c.channels)); let total = u16::from(c.streams) + u16::from(c.coupled_streams); assert!(c.mapping.iter().all(|&m| u16::from(m) < total)); } fuzz_target!(|data: &[u8]| { if let Ok(s) = sdp::parse_sdp(data) { assert!(s.attributes.len() + s.other.len() <= MAX_SDP_LINES); if let Ok(caps) = domistream::rtsp::HostCapabilities::from_sdp(&s) { assert!(caps.opus_configs.len() <= MAX_OPUS_CONFIGS); caps.opus_configs.iter().for_each(valid); } } if let Ok(text) = core::str::from_utf8(data) { if let Ok(c) = sdp::parse_surround_params(text) { valid(&c); } } });