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
2 changes: 1 addition & 1 deletion doc/lib/rs/moq-mux.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ back. This is what `moq import` / `export` and the gateways are built on.
| fMP4 / CMAF | yes | yes | Audio/video unwrapped to `legacy` by default, or passed through as `cmaf` with `with_passthrough`; `wvtt` subtitles import as timed WebVTT text and `stpp` TTML (IMSC timing profile) as `ttml` documents on the broadcast clock, preserving source language and label when present; other subtitle codecs are skipped. |
| MPEG-TS | yes | yes | H.264/H.265; AAC, MP2, AC-3, E-AC-3, Opus up to 7.1; SCTE-35 sections and every other undecoded PES stream (KLV, subtitles, DVB AC-3) as tracks; service tables round-trip. |
| FLV / RTMP | yes | yes | Legacy H.264 + AAC + MP3, plus enhanced-RTMP HEVC, AV1, VP9, Opus, AC-3, E-AC-3, and multitrack. |
| Matroska / WebM | yes | yes | Timed SRT and WebVTT subtitles import as WebVTT text renditions, preserving source language and label when present; other subtitle codecs are skipped. |
| Matroska / WebM | yes | yes | Import streams each block into its frame in one pass, retaining no declared size. It refuses subtitle tracks, CMAF output, and video `BlockGroup`s with fields after their `Block`: remux video as `SimpleBlock`s and extract subtitles separately. |
| Annex-B (H.264, H.265) | yes | yes | Parameter sets extracted to the catalog or re-injected per keyframe. |

Importers fill the catalog from the bitstream, split groups at keyframes, and
Expand Down
1 change: 0 additions & 1 deletion quest/m1/security-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Dropped, with reasons:
## Required

- [fMP4 import streams mdat](/quest/m1/security-audit/fmp4-stream-mdat.md) - a box header declaring a huge size cannot pin importer memory across segments
- [MKV import streams blocks](/quest/m1/security-audit/mkv-stream-blocks.md) - a declared block, metadata master, or ignored element cannot pin importer memory
- [Relay HTTP surface](/quest/m1/security-audit/relay-http.md) - `/fetch` cannot be sniffed as active content, and no web page can reach the ops listener
- [Browser input checks](/quest/m1/security-audit/js-input.md) - room metadata is schema-validated and the http:// fingerprint fetch is aborted and length-checked
- [CI tool pins](/quest/m1/security-audit/ci-pins.md) - binding generators are pinned by commit in one place, and the remaining unpinned installs and broad token grants are fixed
12 changes: 5 additions & 7 deletions quest/m1/security-audit/fmp4-stream-mdat.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ frame cap so a sample can be large. Since
[8d2fa6653a](https://github.com/moq-dev/moq/commit/8d2fa6653a) a fragment can
hold several GOPs, so a fragment-sized cap would also refuse legal input.

Open, for the maintainer before building: `moov` and `moof` are parsed whole
today, so a header declaring a huge one still pins input. Bring options with
a recommendation, such as parsing them incrementally (a `moof` is a run of
small child boxes) or bounding them by the work they describe; a plain byte
cap is ruled out above. Settle this together with the same question in
[MKV import streams blocks](/quest/m1/security-audit/mkv-stream-blocks.md).
`moov` and `moof` are parsed whole today, so a header declaring a huge one
still pins input. Decided 2026-10-28 (maintainer, for both importers): parse
metadata children incrementally, keeping only the fields consumed, with no
blanket byte cap. MKV import does so since
[moq-dev/moq#7234](https://github.com/moq-dev/moq/pull/7234).

Keep `sample::Resolver`'s range checks and `Claimed`'s no-reuse rule. Tests
feed a huge declared `moof`, `moov`, `mdat`, and skipped box in small chunks
Expand All @@ -40,5 +39,4 @@ Public API: none expected. Wire: none.

## Related

- [MKV import streams blocks](/quest/m1/security-audit/mkv-stream-blocks.md) - the same principle for MKV
- [Media fuzz](/quest/m2/media-fuzz.md) - would catch this class of buffer lifetime bug
37 changes: 0 additions & 37 deletions quest/m1/security-audit/mkv-stream-blocks.md

This file was deleted.

75 changes: 75 additions & 0 deletions rs/moq-mux/benches/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,85 @@ fn mkv_chunks(c: &mut Criterion) {
group.finish();
}

/// A one-track VP9 WebM of `total` bytes of keyframe SimpleBlocks, each carrying `payload` bytes.
fn mkv_payload_file(payload: usize, total: usize) -> Vec<u8> {
use webm_iterable::WebmWriter;
use webm_iterable::matroska_spec::{Master, MatroskaSpec, SimpleBlock};

let frame = vec![0x5a; payload];
let blocks: Vec<MatroskaSpec> = (0..total / payload)
.map(|index| SimpleBlock::new_uncheked(&frame, 1, (index % 1024) as i16, false, None, false, true).into())
.collect();
let mut data = Vec::new();
let mut writer = WebmWriter::new(&mut data);
writer
.write(&MatroskaSpec::Ebml(Master::Full(vec![MatroskaSpec::DocType(
"webm".into(),
)])))
.unwrap();
writer.write(&MatroskaSpec::Segment(Master::Start)).unwrap();
writer
.write(&MatroskaSpec::Tracks(Master::Full(vec![MatroskaSpec::TrackEntry(
Master::Full(vec![
MatroskaSpec::TrackNumber(1),
MatroskaSpec::TrackType(1),
MatroskaSpec::CodecID("V_VP9".into()),
]),
)])))
.unwrap();
// Relative block timestamps are 16-bit, so each cluster holds a bounded run of them.
for (cluster, blocks) in blocks.chunks(1024).enumerate() {
let mut children = vec![MatroskaSpec::Timestamp(cluster as u64 * 1024)];
children.extend_from_slice(blocks);
writer.write(&MatroskaSpec::Cluster(Master::Full(children))).unwrap();
}
writer.write(&MatroskaSpec::Segment(Master::End)).unwrap();
writer.flush().unwrap();
drop(writer);
data
}

/// MKV block payloads across payload and transport chunk sizes.
fn mkv_payloads(c: &mut Criterion) {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let _enter = runtime.enter();
let mut group = c.benchmark_group("mkv-payloads");
for payload in [1024, 64 * 1024, 1024 * 1024] {
let data = mkv_payload_file(payload, 4 * 1024 * 1024);
group.throughput(Throughput::Bytes(data.len() as u64));
for chunk in [1500, 64 * 1024, data.len()] {
let id = BenchmarkId::new(format!("payload-{payload}"), format!("chunk-{chunk}"));
group.bench_function(id, |b| {
b.iter_batched(
|| {
let mut broadcast = moq_net::broadcast::Info::new().produce();
let catalog = moq_mux::catalog::Producer::new(&mut broadcast, Default::default()).unwrap();
let import = moq_mux::container::mkv::Import::new(broadcast, catalog.reserve());
(catalog, import)
},
|(catalog, mut import)| {
for bytes in std::hint::black_box(&data).chunks(chunk) {
import.decode(bytes).unwrap();
}
import.finish().unwrap();
(catalog, import)
},
BatchSize::PerIteration,
);
});
}
}
group.finish();
}

criterion_group!(
benches,
containers,
mkv_chunks,
mkv_payloads,
interleaved_runs,
queued_groups,
ts_si_renewal,
Expand Down
12 changes: 12 additions & 0 deletions rs/moq-mux/src/catalog/hang/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ impl TryFrom<&crate::catalog::VideoHint> for Container {
}
}

impl Container {
/// The bytes preceding a frame's payload, when they depend on nothing but its timestamp, so the
/// payload can stream in after them. `None` for CMAF, whose `moof` describes the payload.
pub(crate) fn prefix(&self, timestamp: moq_net::Timestamp) -> crate::Result<Option<bytes::Bytes>> {
match self {
Self::Legacy(kind) => legacy::Wire(*kind).prefix(timestamp).map(Some),
Self::Loc(kind) => loc::Wire(*kind).prefix(timestamp).map(Some),
Self::Cmaf(_) => Ok(None),
}
}
}

/// Whether a rendition's frames can be parsed by this build, logging the ones dropped.
///
/// The hang spec requires a consumer to ignore a rendition whose container `kind` it does not
Expand Down
13 changes: 13 additions & 0 deletions rs/moq-mux/src/container/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ pub struct Wire(
pub Kind,
);

impl Wire {
/// The bytes preceding a frame's payload: its varint timestamp.
pub(crate) fn prefix(&self, timestamp: moq_net::Timestamp) -> crate::Result<bytes::Bytes> {
let mut prefix = bytes::BytesMut::new();
hang::container::Frame {
timestamp,
payload: bytes::Bytes::new(),
}
.encode(&mut prefix)?;
Ok(prefix.freeze())
}
}

impl Container for Wire {
type Error = crate::Error;

Expand Down
8 changes: 8 additions & 0 deletions rs/moq-mux/src/container/loc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ pub struct Wire(
pub Kind,
);

impl Wire {
/// The bytes preceding a frame's payload: its property block.
pub(crate) fn prefix(&self, timestamp: Timestamp) -> crate::Result<bytes::Bytes> {
let timestamp = timestamp.convert(DEFAULT_TIMESCALE).map_err(hang::Error::from)?;
Ok(moq_loc::encode(timestamp.value(), &[])?)
}
}

impl Container for Wire {
type Error = crate::Error;

Expand Down
Loading