[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:
@@ -0,0 +1,41 @@
|
||||
//! Fuzzes the video depacketizer with a sequence of datagrams.
|
||||
//! Asserts invariants, not only "no panic": frames stay within MAX_FRAME_BYTES and come out in increasing frame order; lost ranges are forward ranges.
|
||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
||||
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use core::time::Duration;
|
||||
|
||||
use domistream::Instant;
|
||||
use domistream::video::{MAX_FRAME_BYTES, VideoConfig, VideoDepacketizer, VideoEvent};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let cfg = VideoConfig { packet_size: 64, cipher: None, frame_timeout: Duration::from_millis(20) };
|
||||
let Ok(mut d) = VideoDepacketizer::new(cfg) else { return };
|
||||
let mut rest = data;
|
||||
let mut us = 0u64;
|
||||
let mut prev: Option<u32> = None;
|
||||
// Datagrams separated by a 1-byte length; time advances 1 ms per datagram.
|
||||
while let Some((&len, tail)) = rest.split_first() {
|
||||
let len = usize::from(len).min(tail.len());
|
||||
let (g, tail) = tail.split_at(len);
|
||||
rest = tail;
|
||||
us += 1000;
|
||||
let _ = d.push(Instant::from_micros(us), g);
|
||||
let _ = d.handle_timeout(Instant::from_micros(us));
|
||||
while let Some(e) = d.poll_event() {
|
||||
match e {
|
||||
VideoEvent::Frame(f) => {
|
||||
assert!(f.bitstream.len() <= MAX_FRAME_BYTES);
|
||||
if let Some(p) = prev {
|
||||
assert!(f.frame_index.wrapping_sub(p).wrapping_sub(1) < 1 << 31, "frame order");
|
||||
}
|
||||
prev = Some(f.frame_index);
|
||||
}
|
||||
VideoEvent::FrameLost { first, last } => assert!(last.wrapping_sub(first) < 1 << 31),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user