Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ moq-vaapi = "0.1.0"
# that argument, so moq-ffi and moq-c opt NVIDIA and VAAPI back in (OpenH264
# through their own `openh264` feature, which release builds enable).
moq-video = { version = "0.1.10", path = "rs/moq-video", default-features = false }
mp4-atom = "0.17.0"
mp4-atom = "0.17.1"
nix = { version = "0.31.3", features = ["net", "socket", "uio"] }
num_enum = "0.7"
objc2 = "0.6.4"
Expand Down
2 changes: 0 additions & 2 deletions quest/m1/fuzz-findings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ fixed the MKV block-header panic; its input is

## Required

- [moq-mux on a fixed mp4-atom](/quest/m1/fuzz-findings/mp4-atom-bump.md) - waiting on a 0.17.x release containing kixelated/mp4-atom#264 and #267, then moq-mux bumps to it and commits the `sgpd`, `iref` and `iloc` regressions
- [mp4-atom iloc is bounded](/quest/m1/fuzz-findings/mp4-atom-iloc.md) - zero-size `iloc` extents cannot allocate megabytes from a few bytes; fixed upstream by kixelated/mp4-atom#267, finished by the mp4-atom bump
- [A catalog update reuses its encoder](/quest/m1/fuzz-findings/catalog-encoder.md) - republishing a compressed catalog or HLS group stops allocating a fresh DEFLATE encoder (about 200 KB) each time
39 changes: 0 additions & 39 deletions quest/m1/fuzz-findings/mp4-atom-bump.md

This file was deleted.

33 changes: 0 additions & 33 deletions quest/m1/fuzz-findings/mp4-atom-iloc.md

This file was deleted.

13 changes: 13 additions & 0 deletions rs/moq-mux/fuzz/regressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ stable toolchain as part of `just check`, allocation bound included, so a bug fo
fuzzing stays fixed without anyone running the fuzzer again.

See [../README.md](../README.md) for the workflow.

## mp4-atom inputs

`cmaf/mp4-atom-{sgpd,iref,iloc}` preserve the minimized inputs from
[the fuzz findings](https://github.com/moq-dev/moq/pull/7313#issuecomment-6520535160),
including the two-byte init length. Their `fmp4/` counterparts replace that length
with a zero write-size selector and wrap the atoms in a `moov` box: streaming
ingest skips other top-level boxes. Both paths replay the malformed metadata with
the allocation bound enabled.

mp4-atom 0.17.1 contains the `sgpd` entry-count and zero-size `iloc` extent
bounds; 0.17.0 already fixed the `iref` subtraction overflow. moq-mux keeps its aggregate
sample-group budget and relies on the dependency for per-entry bounds.
Binary file added rs/moq-mux/fuzz/regressions/cmaf/mp4-atom-iloc
Binary file not shown.
Binary file added rs/moq-mux/fuzz/regressions/cmaf/mp4-atom-iref
Binary file not shown.
Binary file added rs/moq-mux/fuzz/regressions/cmaf/mp4-atom-sgpd
Binary file not shown.
Binary file added rs/moq-mux/fuzz/regressions/fmp4/mp4-atom-iloc
Binary file not shown.
Binary file added rs/moq-mux/fuzz/regressions/fmp4/mp4-atom-iref
Binary file not shown.
Binary file added rs/moq-mux/fuzz/regressions/fmp4/mp4-atom-sgpd
Binary file not shown.
35 changes: 26 additions & 9 deletions rs/moq-mux/src/container/fmp4/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,25 +768,25 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
let (mut config, colr, pasp, spatial) = match codec {
mp4_atom::Codec::Avc1(avc1) => (
self.init_h264(false, &avc1.avcc, &avc1.visual, container)?,
avc1.colr.as_ref(),
avc1.colr.as_slice(),
avc1.pasp.as_ref(),
avc1.spatial.as_deref(),
),
mp4_atom::Codec::Avc3(avc3) => (
self.init_h264(true, &avc3.avcc, &avc3.visual, container)?,
avc3.colr.as_ref(),
avc3.colr.as_slice(),
avc3.pasp.as_ref(),
avc3.spatial.as_deref(),
),
mp4_atom::Codec::Hev1(hev1) => (
self.init_h265(true, &hev1.hvcc, &hev1.visual, container)?,
hev1.colr.as_ref(),
hev1.colr.as_slice(),
hev1.pasp.as_ref(),
hev1.spatial.as_deref(),
),
mp4_atom::Codec::Hvc1(hvc1) => (
self.init_h265(false, &hvc1.hvcc, &hvc1.visual, container)?,
hvc1.colr.as_ref(),
hvc1.colr.as_slice(),
hvc1.pasp.as_ref(),
hvc1.spatial.as_deref(),
),
Expand All @@ -803,7 +803,12 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
config.coded_width = Some(vp08.visual.width as _);
config.coded_height = Some(vp08.visual.height as _);
config.container = container;
(config, vp08.colr.as_ref(), vp08.pasp.as_ref(), vp08.spatial.as_deref())
(
config,
vp08.colr.as_slice(),
vp08.pasp.as_ref(),
vp08.spatial.as_deref(),
)
}
mp4_atom::Codec::Vp09(vp09) => {
// https://github.com/gpac/mp4box.js/blob/325741b592d910297bf609bc7c400fc76101077b/src/box-codecs.js#L238
Expand All @@ -824,22 +829,34 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
config.coded_width = Some(vp09.visual.width as _);
config.coded_height = Some(vp09.visual.height as _);
config.container = container;
(config, vp09.colr.as_ref(), vp09.pasp.as_ref(), vp09.spatial.as_deref())
(
config,
vp09.colr.as_slice(),
vp09.pasp.as_ref(),
vp09.spatial.as_deref(),
)
}
mp4_atom::Codec::Av01(av01) => {
let mut config = VideoConfig::new(crate::codec::av1::av1_from_av1c(&av01.av1c));
config.color = crate::codec::av1::color(&av01.av1c.config_obus);
config.coded_width = Some(av01.visual.width as _);
config.coded_height = Some(av01.visual.height as _);
config.container = container;
(config, av01.colr.as_ref(), av01.pasp.as_ref(), av01.spatial.as_deref())
(
config,
av01.colr.as_slice(),
av01.pasp.as_ref(),
av01.spatial.as_deref(),
)
}
mp4_atom::Codec::Unknown(unknown, _) => return Err(Error::UnknownCodec(*unknown).into()),
unsupported => return Err(Error::UnsupportedCodec(Box::new(unsupported.clone())).into()),
};
// The codec config outranks the colr box a muxer added, which only fills its gaps.
let colr = colr.map(super::colr_color).transpose()?.flatten();
crate::codec::color::fill(&mut config.color, colr.as_ref(), "colr");
for entry in colr {
let color = super::colr_color(entry)?;
crate::codec::color::fill(&mut config.color, color.as_ref(), "colr");
}
(config.projection, config.stereo) = super::spatial(spatial)?;
if let Some(pasp) = pasp {
let width = config.coded_width.ok_or(Error::InvalidAspect("missing width"))?;
Expand Down
19 changes: 18 additions & 1 deletion rs/moq-mux/src/container/fmp4/import_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3659,6 +3659,23 @@ fn colr_fills_what_the_sps_leaves_unsaid() {
assert_eq!(video.color, Some(color(9, 16, 9, true)));
}

/// ICC profiles do not hide the CICP colour carried by another colr box.
#[test]
fn colr_after_an_icc_profile_fills_the_catalog() {
let init = avc1_init(crate::codec::h264::fixtures::SPS_IPB, Some(color(9, 16, 9, true)));
let (ftyp, mut moov) = decode_init(&init);
let mp4_atom::Codec::Avc1(avc1) = &mut moov.trak[0].mdia.minf.stbl.stsd.codecs[0] else {
panic!("expected avc1");
};
avc1.colr.insert(0, mp4_atom::Colr::Prof { profile: vec![1, 2, 3] });
let mut init = Vec::new();
ftyp.encode(&mut init).unwrap();
moov.encode(&mut init).unwrap();
let catalog = run_fmp4(&init);
let video = catalog.video.renditions.values().next().unwrap();
assert_eq!(video.color, Some(color(9, 16, 9, true)));
}

/// A source that signals no colour adds no catalog field and no colr box.
#[test]
fn unsignalled_color_stays_absent() {
Expand All @@ -3667,7 +3684,7 @@ fn unsignalled_color_stays_absent() {
let mp4_atom::Codec::Avc1(avc1) = &moov.trak[0].mdia.minf.stbl.stsd.codecs[0] else {
panic!("expected avc1");
};
assert_eq!(avc1.colr, None);
assert!(avc1.colr.is_empty());

let catalog = run_fmp4(&init);
let video = catalog.video.renditions.values().next().unwrap();
Expand Down
58 changes: 6 additions & 52 deletions rs/moq-mux/src/container/fmp4/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl Scan {
self.groups += sgpd(data)?;
return Ok(());
}
b"iloc" => return iloc(data),
b"moov" | b"trak" | b"mdia" | b"minf" | b"stbl" | b"dinf" | b"edts" | b"mvex" | b"moof" | b"traf"
| b"mfra" | b"iprp" | b"ipco" => Namespace::Any,
b"udta" => Namespace::Udta,
Expand Down Expand Up @@ -231,8 +230,7 @@ fn take<'a>(data: &mut &'a [u8], size: usize) -> Result<&'a [u8]> {
Ok(body)
}

// mp4-atom 0.17.0 still accepts zero-byte descriptions. Keep the upstream #264 bound here
// until our dependency includes it: every entry must be paid for by at least one input byte.
// Count descriptions across boxes before allocating the metadata tree.
fn sgpd(mut data: &[u8]) -> Result<u64> {
let version = u32::decode(&mut data)? >> 24;
take(&mut data, 4)?; // grouping_type
Expand All @@ -243,56 +241,9 @@ fn sgpd(mut data: &[u8]) -> Result<u64> {
take(&mut data, 4)?; // default_group_description_index
}
let count = u32::decode(&mut data)?;
if count as usize > data.len() {
return Err(mp4_atom::Error::OutOfBounds.into());
}
Ok(count.into())
}

// The same dependency also lacks #267. A single zero-size extent names the whole reference;
// several would allocate without consuming input, and are refused before decoding any item.
fn iloc(mut data: &[u8]) -> Result<()> {
let version = u32::decode(&mut data)? >> 24;
let sizes0 = u8::decode(&mut data)?;
let sizes1 = u8::decode(&mut data)?;
let offset = sizes0 >> 4;
let length = sizes0 & 15;
let base = sizes1 >> 4;
let index = if version == 0 { 0 } else { sizes1 & 15 };
if version > 2
|| [offset, length, base, index]
.iter()
.any(|size| ![0, 4, 8].contains(size))
{
return Err(mp4_atom::Error::InvalidSize.into());
}
let count = if version < 2 {
u32::from(u16::decode(&mut data)?)
} else {
u32::decode(&mut data)?
};
for _ in 0..count {
take(
&mut data,
if version == 0 {
4
} else if version == 1 {
6
} else {
8
},
)?;
take(&mut data, base as usize)?;
let extents = u16::decode(&mut data)? as usize;
let width = usize::from(offset + length + index);
if width == 0 && extents > 1 {
return Err(mp4_atom::Error::OutOfBounds.into());
}
take(&mut data, extents * width)?;
}
Ok(())
}

#[cfg(test)]
pub(crate) mod tests {
use super::*;
Expand Down Expand Up @@ -398,7 +349,7 @@ pub(crate) mod tests {
data.extend_from_slice(&0u32.to_be_bytes());
}
data.extend_from_slice(&1u32.to_be_bytes());
assert!(check(&boxed(b"sgpd", &data)).is_err());
assert!(mp4_atom::Any::decode(&mut boxed(b"sgpd", &data).as_slice()).is_err());
}
for version in 0..=2 {
for count in [1u16, 2] {
Expand All @@ -419,7 +370,10 @@ pub(crate) mod tests {
}
]);
data.extend_from_slice(&count.to_be_bytes());
assert_eq!(check(&boxed(b"iloc", &data)).is_ok(), count == 1);
assert_eq!(
mp4_atom::Any::decode(&mut boxed(b"iloc", &data).as_slice()).is_ok(),
count == 1
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-mux/src/container/fmp4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ pub(crate) fn synthesize_video_trak(
// Codecs that carry an out-of-band config record require `description`.
let require_description = || description.ok_or_else(|| Error::MissingVideoDescription(config.codec.to_string()));

let colr = color_colr(config.color.as_ref());
let colr = color_colr(config.color.as_ref()).into_iter().collect();
let sample_entry = match &config.codec {
VideoCodec::H264(h264) => {
let mut cursor = std::io::Cursor::new(require_description()?);
Expand Down
Loading