From ad914cd41d8e65f1edf1319d6aae2bb289275dee Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 5 Nov 2026 06:46:57 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m1/fuzz-findings/README.md Quest-Claim: b2043dcd63eb88d1 From 6da6455b093f9237eeb39a6828417298fea7befe Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 5 Nov 2026 12:23:10 -0800 Subject: [PATCH 2/2] fix(mux,quic): clear the fmp4 and connection fuzz findings fmp4: a `trun` without per-sample fields stores only a count, so a 104-byte moof planned 65,792 samples (7 MB) before any payload arrived, breaking the fuzz target's allocation bound. A fragment now declares at most one sample per byte of its metadata past 4,096, besides MAX_FRAGMENT_SAMPLES. connection: the harness stopped tainting a tampered datagram at the first packet whose tag held the first changed byte, so a later coalesced packet's corrupted DATAGRAM frame tripped the check. Later packets are now decoded. Commits the nightly inputs for both, and the 2026-11-04 cmaf OOM input that moq-dev/moq#7843 fixed. Updates the fuzz findings epic with the triage. Co-Authored-By: Claude Opus 5.5 --- quest/m1/fuzz-findings/README.md | 46 ++++++++++-------- rs/moq-mux/CHANGELOG.md | 1 + .../fuzz/regressions/cmaf/metadata-preflight | Bin 0 -> 816 bytes .../regressions/fmp4/fieldless-trun-count | Bin 0 -> 2036 bytes rs/moq-mux/src/container/fmp4/import.rs | 32 +++++++++--- rs/moq-mux/src/container/fmp4/metadata.rs | 22 ++++++--- rs/moq-mux/src/container/fmp4/mod.rs | 20 +++++--- ...h-a0ef11af573b106e4f66ab4007f9f5ebc61cffee | Bin 0 -> 966 bytes rs/moq-quic/src/fuzz/connection.rs | 7 +-- 9 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 rs/moq-mux/fuzz/regressions/cmaf/metadata-preflight create mode 100644 rs/moq-mux/fuzz/regressions/fmp4/fieldless-trun-count create mode 100644 rs/moq-quic/fuzz/regressions/connection/crash-a0ef11af573b106e4f66ab4007f9f5ebc61cffee 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 0000000000000000000000000000000000000000..0deb7158b8ee771129bcd783be6b01b0bc81e12a GIT binary patch literal 816 zcmZRoXJBA>Q=DFq0;Cx-i}Q1V*etie#1P08DM?EyVFXElfktjwY6Xy`P*Mb@L4sge z5Rp|@U|<0f0Rn^;2%mw`f#Cy#2b2S$m|vi985k5ZQgVu5Vr7{rsW3K-{+7#tp@{>V zCdN9L76yiIxtV!sK(0y(h~{9BNhwMN@j(FOOrFxB{~+g~0{q5~1`;^5@COo53Gre7 kVFM7Tg9t1DWErD(Zc1h%D8fWaXlF8VYR62mAn$kp02>~R&;S4c literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f488882380bf7ed3fc59c01723571854596460d2 GIT binary patch literal 2036 zcmb_cO=uHQ5T4ylDq_)8QfXS^qA3 zQ1Ivvf~=ahVofoLmO0-g%GhH;4RXpQjD&~hpYvY`d*Ix#~Y$6nAE_GLBQ;u3zG zoR%)j#J3Obkh>F!J@SxgPUvZQB%g}QPNFZK?1_^;jy}SWk;`XLh&l$(1&S4a35CuHwBm&g5uz;E* zMjaG1Xj_wf(J7eorGT|iC=Xhg@E#gGGR z9Y4(n`q+%wTvz(w+)nxCQJkOi%}GR`lv&jYvnzlCL9>JeUU8u8;4vtRmI=o4pqSoI zuC+j6o5j38%&I^kd7y~chF)$e1z80k;FSl6^8r9i;+0jsomA@$=E|cF* z`>B>z@=%K!qq4`0H0Pvk_upD89-IG;;ja$Twa@6TTcj`X~3c`Wx|JoNtd^EX!>J)8f%yA#2Pk7D^hdh^D> z?ESgey*pgD=@c}~K#Ky06`>8JClGOA48%Uz@Ci 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 0000000000000000000000000000000000000000..b45e537dcd55afd5d5830b861c8fb8e21bc7ee42 GIT binary patch literal 966 zcmb2&cS2-ix2%ud>Y6u>40SB~xn{Upv%M*8TBX^c6ZE=nlhKys2q9xb)fZdW+4j}B z&RlT6spLt=pNI#^3XkgG4CMz1|6NgihRDyrGNW7jO{CG}QXL?zG>} zFrnkM7~cxH$w~|6Yn|&bH-6yd)RXh%y2R3dL9cBkSiRpKUrLw2!wkDT>|tjuI<@7X zQtr1m=Z~CPake@c8t+?|ZQd*+V{h6Di}GU)9$ma8n~d)e3^Y(Gfd(3(Fhhjbz4(O7 zM28n6G*OV9&@mGm?ZWFwSY~SHd;X86?&l*CTi!38_5Uo>)DwCCt~Javj^_jb?hDGY literal 0 HcmV?d00001 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 {