[domistream] Tests: fuzz targets assert invariants
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).
This commit is contained in:
@@ -1,23 +1,37 @@
|
||||
//! Fuzzes the RTSP framer over a chunked byte stream: never panics, whatever the bytes.
|
||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
||||
//! 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 chunk = usize::from(chunk).max(1);
|
||||
let mut framer = domistream::rtsp::RtspFramer::new();
|
||||
for piece in rest.chunks(chunk) {
|
||||
if framer.push(piece).is_err() {
|
||||
return;
|
||||
}
|
||||
while let Ok(Some(message)) = framer.next_message() {
|
||||
let _ = domistream::rtsp::parse_response(&message);
|
||||
}
|
||||
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());
|
||||
}
|
||||
let _ = framer.finish();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user