Reference keyframes per track, size the DTS reserve, correct two claims

The ReferenceBlock offset was computed for ANY video track, but the keyframe tick
it measures against was recorded in a single global slot gated to the PRIMARY
video track. On a title with two video tracks — an MVC base plus secondary view,
or a multi-angle disc — a secondary track's non-keyframe therefore referenced a
keyframe on a different track, or 0 (a self-reference) when the primary had not
produced one yet. The tick is now recorded per track, so a non-keyframe can only
reference a keyframe on its own track.

The faststart moov-hole estimate modelled every audio track as (E-)AC-3 at 1536
samples per frame. 1.6.0 added DTS to the writer's carried set, and a DTS core AU
is commonly 512 samples — a third of that — so a DTS track's sample table was
under-reserved threefold and the mux fell back to moov-at-end, losing faststart
on exactly the files 1.6.0 newly supports.

mvc_frame_emits_blockgroup_additional_and_reference asserted only that the
non-keyframe's ReferenceBlock was Some(_). Its non-MVC sibling, added in the same
commit, pins the exact offset; this one now does too, so a mutant emitting a
constant or wrong-signed offset no longer passes.

The comment above the mp4 sample budget claimed file_len stops a crafted file
inflating allocations "past the file's own size". Each indexed sample costs ~52
bytes, so the real ceiling is ~52x file_len (still capped by MAX_SAMPLE_COUNT).
The bound is real; the comment overstated how tight it is.
This commit is contained in:
Matthew Jackson
2026-07-29 19:03:59 -07:00
parent d4c913e0d3
commit 99c5fd3500
3 changed files with 50 additions and 16 deletions
+11 -2
View File
@@ -82,8 +82,17 @@ fn estimate_reserve(title: &DiscTitle, included: &[usize]) -> u64 {
est_samples += dur * fps;
}
DiscStream::Audio(a) => {
// ~1536 samples per (E-)AC-3 frame.
est_samples += dur * (a.sample_rate.hz() / 1536.0);
// Samples per frame differs sharply by codec, and 1.6.0 added DTS
// to the carried set (audio_fits now admits Dts | DtsHdMa |
// DtsHdHr). A DTS core AU is (nblks+1)*32 — commonly 512 samples,
// a third of an (E-)AC-3 frame's 1536 — so modelling every audio
// track as AC-3 under-reserved a DTS track's sample table 3x and
// pushed the mux onto the moov-at-end fallback.
let samples_per_frame = match a.codec {
Codec::Dts | Codec::DtsHdMa | Codec::DtsHdHr => 512.0,
_ => 1536.0,
};
est_samples += dur * (a.sample_rate.hz() / samples_per_frame);
}
DiscStream::Subtitle(_) => {}
}