diff --git a/quest/m1/fuzz-findings/README.md b/quest/m1/fuzz-findings/README.md index f80f6e21003..6878a9b6694 100644 --- a/quest/m1/fuzz-findings/README.md +++ b/quest/m1/fuzz-findings/README.md @@ -11,21 +11,32 @@ Each fixed finding's minimized input is committed under the target's ## Plan [moq-dev/moq#7313](https://github.com/moq-dev/moq/pull/7313) added the -targets and landed with six nightly jobs red (decided 2026-10-30, -maintainer). Its short local runs found the bugs the children fix; the -minimized inputs are in [its PR comment](https://github.com/moq-dev/moq/pull/7313#issuecomment-6520535160). - -Each child commits its input under `regressions/` with its fix, since an -input committed before the fix would fail the merge gate. Every known finding -is now fixed: run every target nightly for a few sessions; a new finding -becomes a child here. - -Decided 2026-11-05 (maintainer, /quest-plan): keep this epic as an `[S]` watcher after -[moq-dev/moq#7690](https://github.com/moq-dev/moq/pull/7690) removed its last -child, since Fuzz (annexb), (fmp4), (ts), and (ingest) were still red on -2026-11-05. An agent triages each red target into a child quest (an -intermittent failure joins m0's test flakes instead), and the epic is deleted -once every target runs green. Not chosen: deleting it now. +targets, and its children fixed the findings from its short local runs. +Each fix commits its input under `regressions/` with the fix, since an +input committed before the fix would fail the merge gate. + +Decided 2026-11-05 (maintainer, /quest-plan): this epic stays an `[S]` +watcher. An agent triages each red target into a child quest; an +intermittent failure joins m0's [test flakes](/quest/m0/test-flakes-2/README.md) +instead. The epic is deleted once every target runs green. Not chosen: +deleting it once its last child merged. + +Triage of the 2026-11-03 to 2026-11-05 scheduled runs +([moq-dev/moq#7961](https://github.com/moq-dev/moq/pull/7961)): + +- `annexb` (scuffle-h265 SPS overflow) and `ts` (step look-ahead overflow), + 2026-11-03: fixed by [moq-dev/moq#7685](https://github.com/moq-dev/moq/pull/7685) + and [moq-dev/moq#7683](https://github.com/moq-dev/moq/pull/7683), which + committed the inputs. +- `cmaf` (out of memory on received metadata), 2026-11-04: fixed by + [moq-dev/moq#7843](https://github.com/moq-dev/moq/pull/7843); moq-dev/moq#7961 + commits its input as `cmaf/metadata-preflight`. +- `fmp4` (allocation bound), 2026-11-04 and 2026-11-05: a field-less `trun` + declared 65,792 samples in a 104-byte `moof`. Fixed in moq-dev/moq#7961 by + holding a fragment to one sample per metadata byte past a base. + +What remains: watch the next scheduled runs. When every media target has +run green, delete this epic. A new finding becomes a child here. For the crates outside the `kixelated` and `moq-dev` orgs, moq-mux fixes the bug on its own side and the bug is reported upstream (decided @@ -35,8 +46,3 @@ the bug on its own side and the bug is reported upstream (decided (scuffle-h265), and [ScuffleCloud/scuffle#654](https://github.com/ScuffleCloud/scuffle/issues/654) (scuffle-expgolomb). Posting anything further on those repos still needs the maintainer's approval. - -[moq-dev/moq#7234](https://github.com/moq-dev/moq/pull/7234) replaced -webm-iterable's block parsing with moq-mux's own block-header reader, which -fixed the MKV block-header panic; its input is -`rs/moq-mux/fuzz/regressions/mkv/short-block-header`. diff --git a/rs/moq-mux/CHANGELOG.md b/rs/moq-mux/CHANGELOG.md index a9216f84097..b1e88798335 100644 --- a/rs/moq-mux/CHANGELOG.md +++ b/rs/moq-mux/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- A `moof` declares at most one sample per byte of its metadata past 4,096, besides `fmp4::MAX_FRAGMENT_SAMPLES`, or it is refused with `Error::TooManySamples` before planning. A run without per-sample fields stores only a count, so a 104-byte `moof` could plan 65,792 samples (7 MB) before any payload arrived; every run with per-sample fields already pays at least 4 bytes a sample. - Received CMAF init segments and fragments use the importer's metadata and sample limits before mp4-atom parses any box, including discarded known types and the children it keeps from spatial sample-entry boxes. MSF catalog derivation and regular MP4 recording share the checks; zero-byte entry counts cannot amplify a small input. - fMP4 import bounds what a `moov` or `moof` costs to parse and plan: a body over `fmp4::MAX_METADATA_BYTES` (2 MiB) is refused at its header, since parsing expands it up to tenfold, a `moof` of more than `fmp4::MAX_FRAGMENT_SAMPLES` (now 131,072) samples is refused before planning, and a `moov` of more than `fmp4::MAX_TRACKS` (256) tracks with `Error::TooManyTracks` before any is created. `fmp4::MAX_HELD_BYTES` (32 MiB) now bounds only a text sample. A 116-byte `moof` no longer plans 584 MB. diff --git a/rs/moq-mux/fuzz/regressions/cmaf/metadata-preflight b/rs/moq-mux/fuzz/regressions/cmaf/metadata-preflight new file mode 100644 index 00000000000..0deb7158b8e Binary files /dev/null and b/rs/moq-mux/fuzz/regressions/cmaf/metadata-preflight differ diff --git a/rs/moq-mux/fuzz/regressions/fmp4/fieldless-trun-count b/rs/moq-mux/fuzz/regressions/fmp4/fieldless-trun-count new file mode 100644 index 00000000000..f488882380b Binary files /dev/null and b/rs/moq-mux/fuzz/regressions/fmp4/fieldless-trun-count differ diff --git a/rs/moq-mux/src/container/fmp4/import.rs b/rs/moq-mux/src/container/fmp4/import.rs index 7552c86dcc3..d11125c7c14 100644 --- a/rs/moq-mux/src/container/fmp4/import.rs +++ b/rs/moq-mux/src/container/fmp4/import.rs @@ -355,9 +355,9 @@ impl Import { /// bounded: a `moov` or `moof` body larger than /// [`MAX_METADATA_BYTES`](super::MAX_METADATA_BYTES), or a text sample larger than /// [`MAX_HELD_BYTES`](super::MAX_HELD_BYTES), is refused before it is held. A `moof` declaring - /// more than [`MAX_FRAGMENT_SAMPLES`](super::MAX_FRAGMENT_SAMPLES) samples is refused before - /// they are planned, and a `moov` declaring more than [`MAX_TRACKS`](super::MAX_TRACKS) - /// tracks before any is created. + /// more than [`MAX_FRAGMENT_SAMPLES`](super::MAX_FRAGMENT_SAMPLES) samples, or more than its + /// size accepts, is refused before they are planned, and a `moov` declaring more than + /// [`MAX_TRACKS`](super::MAX_TRACKS) tracks before any is created. /// /// A decode error is terminal: later decodes, cuts, seeks and discontinuities return the same /// error without reading input or changing the tracks. @@ -2100,10 +2100,18 @@ mod tests { import.finish().unwrap(); } - // At the bound, the moof is accepted. - let (mut import, id, _) = initialized(false); - import.decode(&inherited_moof(id, &[half, half])).unwrap(); + // A short moof declares one field-less sample per body byte past the base, and no more. + let (_, id, _) = initialized(false); + let fit = (super::super::FRAGMENT_SAMPLE_BASE as usize + inherited_moof(id, &[0]).len() - 8) as u32; + let (mut import, _, _) = initialized(false); + import.decode(&inherited_moof(id, &[fit])).unwrap(); assert!(import.moof.is_some()); + let (mut import, _, _) = initialized(false); + let err = import.decode(&inherited_moof(id, &[fit + 1])).unwrap_err(); + assert!( + matches!(err, crate::Error::Cmaf(Error::TooManySamples(count)) if count == u64::from(fit) + 1), + "{err:?}" + ); } /// A fragment within the bounds plans within [`MAX_HELD_BYTES`](super::super::MAX_HELD_BYTES) @@ -2145,12 +2153,22 @@ mod tests { .collect() }; let start = runs_moof(id, gapped(0)).len() + 8; + // Field-less samples past the base need a byte each, which entries supply here. + let mut paid = entries(MAX_FRAGMENT_SAMPLES as usize / 4, small); + paid.push(mp4_atom::Trun { + data_offset: None, + samples: mp4_atom::TrunSamples::Inherited { + count: (MAX_FRAGMENT_SAMPLES - MAX_FRAGMENT_SAMPLES / 4) as u32, + first_flags: None, + }, + }); let inputs = [ ( "field-less runs", inherited_moof(id, &[MAX_FRAGMENT_SAMPLES as u32]), - None, + Some(MAX_FRAGMENT_SAMPLES as usize), ), + ("field-less runs paid in bytes", runs_moof(id, paid), None), ("full entries", runs_moof(id, entries(room / 16, full)), None), ( "4-byte entries", diff --git a/rs/moq-mux/src/container/fmp4/metadata.rs b/rs/moq-mux/src/container/fmp4/metadata.rs index 6dee8d2de80..e8a3fe28de0 100644 --- a/rs/moq-mux/src/container/fmp4/metadata.rs +++ b/rs/moq-mux/src/container/fmp4/metadata.rs @@ -5,20 +5,20 @@ use mp4_atom::{Decode, FourCC, Header}; -use super::{Error, MAX_FRAGMENT_SAMPLES, MAX_METADATA_BYTES, MAX_TRACKS, Result}; +use super::{Error, FRAGMENT_SAMPLE_BASE, MAX_FRAGMENT_SAMPLES, MAX_METADATA_BYTES, MAX_TRACKS, Result}; /// Check every box, including ones a caller or mp4-atom will discard. pub(crate) fn check(data: &[u8]) -> Result<()> { let mut scan = Scan::default(); scan.boxes(data, Namespace::Any)?; - scan.finish() + scan.finish(data.len()) } /// Check a body already framed by the streaming importer. pub(super) fn body(kind: FourCC, data: &[u8]) -> Result<()> { let mut scan = Scan::default(); scan.body(kind, data)?; - scan.finish() + scan.finish(data.len()) } #[derive(Clone, Copy)] @@ -43,8 +43,9 @@ struct Scan { } impl Scan { - fn finish(self) -> Result<()> { - if self.samples > MAX_FRAGMENT_SAMPLES { + /// Check the counts gathered from `len` bytes of metadata. + fn finish(self, len: usize) -> Result<()> { + if self.samples > MAX_FRAGMENT_SAMPLES.min(FRAGMENT_SAMPLE_BASE + len as u64) { return Err(Error::TooManySamples(self.samples)); } if self.groups > MAX_FRAGMENT_SAMPLES { @@ -278,8 +279,17 @@ pub(crate) mod tests { #[test] fn counts_are_checked_across_runs_and_tracks_before_parsing() { + // A field-less run stores only a count, so a short moof gets one sample per byte past the base. + let short = |count| check(&boxed(b"moof", &boxed(b"traf", &inherited(count)))); + let fit = (FRAGMENT_SAMPLE_BASE as usize + boxed(b"moof", &boxed(b"traf", &inherited(0))).len()) as u32; + short(fit).unwrap(); + assert!(matches!(short(fit + 1), Err(Error::TooManySamples(count)) if count == u64::from(fit) + 1)); + + // Bytes the moof carries, here a padding box, pay for samples up to the cap, which sums + // across runs and tracks. let half = (MAX_FRAGMENT_SAMPLES / 2) as u32; - let mut data = boxed(b"traf", &inherited(half)); + let mut data = boxed(b"free", &vec![0; MAX_FRAGMENT_SAMPLES as usize]); + data.extend(boxed(b"traf", &inherited(half))); data.extend(boxed(b"traf", &inherited(half))); check(&boxed(b"moof", &data)).unwrap(); data.extend(boxed(b"traf", &inherited(1))); diff --git a/rs/moq-mux/src/container/fmp4/mod.rs b/rs/moq-mux/src/container/fmp4/mod.rs index 53d6d7f108b..9fb800207fa 100644 --- a/rs/moq-mux/src/container/fmp4/mod.rs +++ b/rs/moq-mux/src/container/fmp4/mod.rs @@ -46,10 +46,18 @@ pub const MAX_METADATA_BYTES: usize = MAX_HELD_BYTES / 16; /// /// Every sample's byte range is resolved before any of the fragment publishes, at about 200 bytes /// a sample, so a fragment at this bound plans within [`MAX_HELD_BYTES`]. A `moof` at -/// [`MAX_METADATA_BYTES`] holds this many 16-byte `trun` entries; a run without per-sample fields -/// could otherwise declare billions of samples in a few bytes. +/// [`MAX_METADATA_BYTES`] holds this many 16-byte `trun` entries. A shorter fragment is also held +/// to one sample per metadata byte past the first 4,096. pub const MAX_FRAGMENT_SAMPLES: u64 = (MAX_METADATA_BYTES / 16) as u64; +/// Samples a fragment may declare beyond one per byte of its metadata. +/// +/// A `trun` entry is at least 4 bytes, so only a run without per-sample fields, which stores just +/// a count, can declare more samples than it has bytes. Its plan is reserved before any payload +/// arrives, so this keeps a few-byte `moof` from planning megabytes. A live fragment is a handful +/// of samples. +pub(crate) const FRAGMENT_SAMPLE_BASE: u64 = 4096; + /// The most tracks [`Import`] accepts from one `moov`, refused before any is created. /// /// Each track costs about 16 KiB to parse and set up, and keeps its catalog entry and output @@ -241,10 +249,10 @@ pub enum Error { #[error("text sample of {0} bytes is more than the {MAX_HELD_BYTES} an importer holds")] TextSampleTooLarge(usize), - /// A fragment declaring more than [`MAX_FRAGMENT_SAMPLES`] is refused before parsing. - /// A `trun` without per-sample fields declares its - /// count in four bytes, so the byte bound alone does not limit it. - #[error("moof declares {0} samples, more than the {MAX_FRAGMENT_SAMPLES} a fragment accepts")] + /// A fragment declaring more than [`MAX_FRAGMENT_SAMPLES`], or more than one sample per byte + /// of its metadata past a small base, is refused before parsing. A `trun` without per-sample + /// fields declares its count in four bytes, so the byte bound alone does not limit it. + #[error("moof declares {0} samples, more than a fragment of its size accepts")] TooManySamples(u64), /// A `moov` declaring more than [`MAX_TRACKS`] tracks is refused before any is created. diff --git a/rs/moq-quic/fuzz/regressions/connection/crash-a0ef11af573b106e4f66ab4007f9f5ebc61cffee b/rs/moq-quic/fuzz/regressions/connection/crash-a0ef11af573b106e4f66ab4007f9f5ebc61cffee new file mode 100644 index 00000000000..b45e537dcd5 Binary files /dev/null and b/rs/moq-quic/fuzz/regressions/connection/crash-a0ef11af573b106e4f66ab4007f9f5ebc61cffee differ diff --git a/rs/moq-quic/src/fuzz/connection.rs b/rs/moq-quic/src/fuzz/connection.rs index 3c08ec8610c..62efbfd2dbc 100644 --- a/rs/moq-quic/src/fuzz/connection.rs +++ b/rs/moq-quic/src/fuzz/connection.rs @@ -257,8 +257,9 @@ impl Peer { /// so a frame they accept is never missed. Over-counting only skips a check. /// /// `from` is the first byte that may differ from what the sender sent. Packets ending - /// before it are untouched, and a change inside a packet's tag alters nothing: the tag - /// is never checked and bounds no packet. + /// before it are untouched, and so are the frames of the packet whose tag holds it: the + /// tag is never checked and bounds no packet. Every later byte may differ, so every later + /// coalesced packet is decoded. fn taint(&mut self, datagram: &[u8], from: usize) { let parser = FixedLengthConnectionIdParser::new(CID_LEN); let mut rest = Some(BytesMut::from(datagram)); @@ -274,7 +275,7 @@ impl Peer { continue; } if start <= from && from + TAG_LEN >= end { - return; + continue; } let Ok(packet) = partial.finish(Some(&Clear)) else {