Files
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

53 lines
1.8 KiB
Rust

//! Fuzzes the ENet client peer: a connecting peer fed a sequence of datagrams.
//! Asserts invariants, not only "no panic": never panics; delivered packets are within MAX_PACKET_BYTES; outgoing datagrams parse and stay within the MTU.
//! 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::enet::protocol::parse_datagram;
use domistream::enet::{EnetClient, EnetConfig, EnetEvent, MAX_PACKET_BYTES};
use domistream::{Instant, RandomSource};
struct Fixed;
impl RandomSource for Fixed {
fn fill(&mut self, dest: &mut [u8]) {
dest.fill(0x5A);
}
}
fuzz_target!(|data: &[u8]| {
let cfg = EnetConfig {
channel_count: 2,
mtu: 1400,
connect_data: 0,
ping_interval: Duration::from_millis(500),
timeout: Duration::from_secs(10),
};
let Ok(mut c) = EnetClient::connect(cfg, Instant::ZERO, &mut Fixed) else { return };
// Datagrams separated by a 2-byte big-endian length; time advances 1 ms per datagram.
let mut rest = data;
let mut ms = 0u64;
while rest.len() >= 2 {
let len = usize::from(u16::from_be_bytes([rest[0], rest[1]])).min(rest.len() - 2);
let (d, tail) = rest[2..].split_at(len);
rest = tail;
ms += 1;
let now = Instant::from_micros(ms * 1000);
let _ = c.handle_datagram(now, d);
let _ = c.handle_timeout(now);
while let Some(out) = c.poll_transmit(now) {
assert!(out.len() <= usize::from(cfg.mtu));
parse_datagram(&out).expect("the client's own datagrams parse");
}
while let Some(e) = c.poll_event() {
if let EnetEvent::Received { data, .. } = e {
assert!(data.len() <= MAX_PACKET_BYTES);
}
}
}
});