[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:
@@ -1,13 +1,32 @@
|
||||
//! Fuzzes SDP payloads and the host capabilities read from them: never panics, whatever the bytes.
|
||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
||||
//! Fuzzes SDP payloads, the host capabilities read from them, and `surround-params` values.
|
||||
//! Asserts invariants, not only "no panic": line and config caps hold; every Opus config obeys RFC 7845's rules.
|
||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
||||
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use domistream::rtsp::sdp::{self, MAX_AUDIO_CHANNELS, MAX_OPUS_CONFIGS, MAX_SDP_LINES, OpusConfig};
|
||||
|
||||
fn valid(c: &OpusConfig) {
|
||||
assert!(c.channels >= 1 && usize::from(c.channels) <= MAX_AUDIO_CHANNELS);
|
||||
assert!(c.coupled_streams <= c.streams && c.streams >= 1);
|
||||
assert_eq!(c.mapping.len(), usize::from(c.channels));
|
||||
let total = u16::from(c.streams) + u16::from(c.coupled_streams);
|
||||
assert!(c.mapping.iter().all(|&m| u16::from(m) < total));
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(sdp) = domistream::rtsp::sdp::parse_sdp(data) {
|
||||
let _ = domistream::rtsp::HostCapabilities::from_sdp(&sdp);
|
||||
if let Ok(s) = sdp::parse_sdp(data) {
|
||||
assert!(s.attributes.len() + s.other.len() <= MAX_SDP_LINES);
|
||||
if let Ok(caps) = domistream::rtsp::HostCapabilities::from_sdp(&s) {
|
||||
assert!(caps.opus_configs.len() <= MAX_OPUS_CONFIGS);
|
||||
caps.opus_configs.iter().for_each(valid);
|
||||
}
|
||||
}
|
||||
if let Ok(text) = core::str::from_utf8(data) {
|
||||
if let Ok(c) = sdp::parse_surround_params(text) {
|
||||
valid(&c);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user