Files
DomiStream/fuzz/fuzz_targets/video_packet.rs
T
mnovak 948f446a13 [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).
2026-11-25 12:51:08 +01:00

25 lines
1.2 KiB
Rust

//! Fuzzes video packets and the frame header.
//! Asserts invariants, not only "no panic": FEC fields are consistent on success, the payload is the rest of the packet, the frame header keeps its raw bytes.
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
#![no_main]
use libfuzzer_sys::fuzz_target;
use domistream::video::packet::{FRAME_HEADER_LEN, MAX_VIDEO_PACKET_BYTES, PAYLOAD_OFFSET, parse_frame_header};
fuzz_target!(|data: &[u8]| {
if let Ok(p) = domistream::video::parse_video_packet(data) {
assert!(data.len() >= PAYLOAD_OFFSET && data.len() <= MAX_VIDEO_PACKET_BYTES);
assert_eq!(p.payload.len() + PAYLOAD_OFFSET, data.len());
let f = p.nv.fec;
assert!(f.data_shards > 0 && f.block_index <= f.last_block_index && f.last_block_index < 4);
let m = domistream::fec::parity_count(usize::from(f.data_shards), f.fec_percentage).expect("a consistent block");
assert!(usize::from(f.shard_index) < usize::from(f.data_shards) + m);
assert!(usize::from(f.data_shards) + m <= domistream::fec::MAX_SHARDS);
}
if let Ok(h) = parse_frame_header(data) {
assert_eq!(&h.raw[..], &data[..FRAME_HEADER_LEN]);
}
});