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
46 changes: 26 additions & 20 deletions quest/m1/fuzz-findings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
1 change: 1 addition & 0 deletions rs/moq-mux/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added rs/moq-mux/fuzz/regressions/cmaf/metadata-preflight
Binary file not shown.
Binary file not shown.
32 changes: 25 additions & 7 deletions rs/moq-mux/src/container/fmp4/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
/// 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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 16 additions & 6 deletions rs/moq-mux/src/container/fmp4/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FRAGMENT_SAMPLE_BASE assumes a fragment is live and short, but this check also governs moq import fmp4 from a file or stdin, where a producer can put the whole stream in one moof. ffmpeg always writes tfhd default size and duration and adds per-sample fields only when a sample differs, while FF_MOV_FLAG_FRAG_KEYFRAME flushes only on video, so an audio-only AC-3 or CBR Opus file arrives as one field-less trun; at ~4,180 samples (≈2 min of AC-3) that file is now refused, where the 131,072 cap accepted ≈70 min.

Technical details
# A long field-less audio fragment is now refused

## Affected sites
- `rs/moq-mux/src/container/fmp4/metadata.rs:48` — `len` is the `moof` body on the streaming path (`import.rs:508`), so the budget is 4096 + body bytes.
- `rs/moq-mux/src/container/fmp4/mod.rs:53-59` — `FRAGMENT_SAMPLE_BASE` and its "A live fragment is a handful of samples" doc.
- `rs/moq-mux/src/container/fmp4/sample.rs:147` — a sample costs at least one `mdat` byte and the claimed ranges are disjoint, so the plan grows with delivered payload; only the reservation happens eagerly at `begin_mdat`.

## Concrete input
`ffmpeg -f lavfi -i sine=frequency=440:duration=180 -c:a ac3 -f mp4 -movflags empty_moov - | moq import fmp4` produces one ~90-byte `moof` whose `trun` carries only a count: `mov_write_tfhd_tag` sets `MOV_TFHD_DEFAULT_SIZE|MOV_TFHD_DEFAULT_DURATION`, `mov_write_trun_tag` adds `MOV_TRUN_SAMPLE_SIZE`/`_DURATION` only if a sample differs, and the `FF_MOV_FLAG_FRAG_KEYFRAME` flush requires `par->codec_type == AVMEDIA_TYPE_VIDEO` (movenc.c ~5734, ~5806, ~7630). AC-3 frames are fixed size and duration, so 5,760 samples > ~4,180.

## Required outcome
Either this file imports, or the limitation is recorded where users read the other refusal conditions (`doc/lib/rs/moq-mux.md`). The fuzz invariant itself is not at risk: one sample needs a byte of payload, so a plan grown with delivered bytes stays proportional.

## Open questions for the human
- Is a single-fragment audio file an intended import, or is the importer only for live/short fragments?
- If it is intended, could the plan be built as `mdat` bytes arrive (`begin_mdat` already has the declared length at `import.rs:1095`, and `write_mdat` walks chunks) instead of reserving it from the declared count?

return Err(Error::TooManySamples(self.samples));
}
if self.groups > MAX_FRAGMENT_SAMPLES {
Expand Down Expand Up @@ -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)));
Expand Down
20 changes: 14 additions & 6 deletions rs/moq-mux/src/container/fmp4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Binary file not shown.
7 changes: 4 additions & 3 deletions rs/moq-quic/src/fuzz/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -274,7 +275,7 @@ impl Peer {
continue;
}
if start <= from && from + TAG_LEN >= end {
return;
continue;
}

let Ok(packet) = partial.finish(Some(&Clear)) else {
Expand Down
Loading