948f446a13
Every target now checks properties instead of only calling the parser: parse -> encode -> parse stability (RTSP request, ENet, input), caps and TooLarge past them, chunking invariance of the framer, XML vs status parser agreement, seal/open round trips, no forged GCM tags. New targets for the parsers and state machines that had none: server_cert_der, enet_client, media_decrypt, video_depacketizer, audio_depacketizer, fec_reconstruct, pairing_session, rtsp_client (25 targets).
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
//! 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<Vec<Vec<u8>>> {
|
|
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::<usize>() <= rest.len());
|
|
}
|
|
});
|