//! Fuzzes the RTSP client state machine with hostile answers. //! Asserts invariants, not only "no panic": the requests it emits always parse, and it never reports Ready before a full exchange. //! How to run: see the comment at the top of `fuzz/Cargo.toml`. #![no_main] use libfuzzer_sys::fuzz_target; use domistream::http::launch::AudioLayout; use domistream::rtsp::client::VideoCodec; use domistream::rtsp::{EncryptionFlags, RtspClient, RtspProgress, StreamConfig, parse_request}; fuzz_target!(|data: &[u8]| { let config = StreamConfig { width: 1920, height: 1080, fps: 60, bitrate_kbps: 20_000, packet_size: 1024, codec: VideoCodec::Hevc, hdr: false, audio: AudioLayout::Stereo, audio_packet_duration_ms: 5, min_fec_packets: 2, reference_frame_invalidation: true, encryption: EncryptionFlags(7), }; let Ok(mut c) = RtspClient::new("rtsp://192.0.2.10:48010", config) else { return }; // Answers separated by NUL bytes. for (answers, answer) in data.split(|b| *b == 0).take(8).enumerate() { if let Some(req) = c.poll_request() { parse_request(&req).expect("the client's requests parse"); } if let Ok(RtspProgress::Ready(_)) = c.handle_response(answer) { assert!(answers >= 6, "Ready after {} answers", answers + 1); } } });