Files
DomiStream/fuzz/fuzz_targets/video_packet.rs
2026-11-25 12:52:38 +01:00

26 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]);
}
});