[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,45 @@
|
||||
//! Fuzzes the audio depacketizer with a sequence of datagrams (FEC on, a Cauchy test matrix).
|
||||
//! Asserts invariants, not only "no panic": never two events for one sequence number in a short run; output stays bounded by the input.
|
||||
//! 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 std::collections::HashSet;
|
||||
|
||||
use domistream::Instant;
|
||||
use domistream::audio::{AudioConfig, AudioDepacketizer, AudioEvent, AudioFec};
|
||||
|
||||
// 1 / (x ^ y) over GF(2^8)/0x11D with x in {0, 1} and y in {2, 3, 4, 5}: a 2 x 4 Cauchy matrix, the same one
|
||||
// tests/common builds with gf::cauchy(2, 4).
|
||||
const MATRIX: [u8; 8] = [0x8e, 0xf4, 0x47, 0xa7, 0xf4, 0x8e, 0xa7, 0x47];
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let cfg = AudioConfig { cipher: None, packet_duration_ms: 5, fec: AudioFec::ParityMatrix(MATRIX), loss_timeout: Duration::from_millis(20) };
|
||||
let Ok(mut d) = AudioDepacketizer::new(cfg) else { return };
|
||||
let mut rest = data;
|
||||
let mut us = 0u64;
|
||||
let mut seen = HashSet::new();
|
||||
let mut out_bytes = 0usize;
|
||||
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() {
|
||||
let seq = match &e {
|
||||
AudioEvent::Packet { sequence, opus, .. } => {
|
||||
out_bytes += opus.len();
|
||||
*sequence
|
||||
}
|
||||
AudioEvent::Lost { sequence } => *sequence,
|
||||
};
|
||||
assert!(seen.insert(seq), "two events for sequence {seq}");
|
||||
}
|
||||
}
|
||||
assert!(out_bytes <= data.len() * 2, "FEC rebuilds packets, but not out of nothing");
|
||||
});
|
||||
Reference in New Issue
Block a user