2021-06-08 08:35:08 +04:00
|
|
|
// Copyright (C) 2021 Scott Lamb <slamb@slamb.org>
|
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
2021-06-08 05:12:45 +04:00
|
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
use std::num::NonZeroU32;
|
|
|
|
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
2022-04-29 02:00:36 +04:00
|
|
|
let mut data = data;
|
2021-06-08 05:12:45 +04:00
|
|
|
let mut depacketizer = retina::codec::Depacketizer::new(
|
|
|
|
"video", "h264", 90_000, None, Some("packetization-mode=1;profile-level-id=64001E;sprop-parameter-sets=Z2QAHqwsaoLA9puCgIKgAAADACAAAAMD0IAA,aO4xshsA")).unwrap();
|
|
|
|
let mut timestamp = retina::Timestamp::new(0, NonZeroU32::new(90_000).unwrap(), 0).unwrap();
|
|
|
|
let mut sequence_number: u16 = 0;
|
2021-08-20 00:16:16 +04:00
|
|
|
let conn_ctx = retina::ConnectionContext::dummy();
|
2022-05-11 20:26:00 +04:00
|
|
|
let stream_ctx = retina::StreamContext::dummy();
|
2021-08-28 03:30:55 +04:00
|
|
|
let pkt_ctx = retina::PacketContext::dummy();
|
2022-04-29 02:00:36 +04:00
|
|
|
loop {
|
|
|
|
let (hdr, rest) = match data.split_first() {
|
|
|
|
Some(r) => r,
|
|
|
|
None => return,
|
|
|
|
};
|
2021-06-08 05:12:45 +04:00
|
|
|
let ts_change = (hdr & 0b001) != 0;
|
|
|
|
let mark = (hdr & 0b010) != 0;
|
|
|
|
let loss = (hdr & 0b100) != 0;
|
|
|
|
let len = usize::from(hdr >> 3);
|
2022-04-29 02:00:36 +04:00
|
|
|
if rest.len() < len {
|
2021-06-08 05:12:45 +04:00
|
|
|
return;
|
|
|
|
}
|
2022-04-29 02:00:36 +04:00
|
|
|
let (payload, rest) = rest.split_at(len);
|
|
|
|
data = rest;
|
2021-06-08 05:12:45 +04:00
|
|
|
if loss {
|
|
|
|
sequence_number = sequence_number.wrapping_add(1);
|
|
|
|
}
|
|
|
|
if ts_change {
|
|
|
|
timestamp = timestamp.try_add(1).unwrap();
|
|
|
|
}
|
2022-04-29 02:00:36 +04:00
|
|
|
let pkt = retina::rtp::ReceivedPacketBuilder {
|
2021-08-28 03:30:55 +04:00
|
|
|
ctx: pkt_ctx,
|
2021-06-08 05:12:45 +04:00
|
|
|
stream_id: 0,
|
|
|
|
timestamp,
|
2021-08-20 00:16:16 +04:00
|
|
|
ssrc: 0,
|
2021-06-08 05:12:45 +04:00
|
|
|
sequence_number,
|
|
|
|
loss: u16::from(loss),
|
2022-04-29 02:00:36 +04:00
|
|
|
payload_type: 96,
|
2021-06-08 05:12:45 +04:00
|
|
|
mark,
|
2022-04-29 02:00:36 +04:00
|
|
|
}
|
|
|
|
.build(payload.iter().copied())
|
|
|
|
.unwrap();
|
2021-06-08 08:30:18 +04:00
|
|
|
//println!("pkt: {:#?}", pkt);
|
2021-06-08 05:12:45 +04:00
|
|
|
if depacketizer.push(pkt).is_err() {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-11 20:26:00 +04:00
|
|
|
while let Some(item) = depacketizer.pull(&conn_ctx, &stream_ctx).transpose() {
|
2021-06-08 05:12:45 +04:00
|
|
|
if item.is_err() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sequence_number = sequence_number.wrapping_add(1);
|
|
|
|
}
|
|
|
|
});
|