Common-duration lookup confuses defaults with observed sample durations

perfloop-oss/mp4ff · Value Kind Confusion

https://perfloop.ai/t/oss/case_84wjw9cydc

Verdict

VERIFIED · settled 2026-11-22 · merged as Eyevinn/mp4ff#729

What happened: The check fails before this change and passes with it.

Hypothesis

A track's common-duration lookup can reject uniformly timed samples or accept samples whose effective durations differ. This gives library callers the wrong timing classification. Consumer frequency and downstream effects are unmeasured.

Fragment.CommonSampleDuration initializes commonDur from trex or the flagged tfhd default. It then treats that fallback as an already observed duration and also passes the changing accumulator back to TrunBox.CommonSampleDuration as the next run's fallback. These are different roles. TrunBox.AddSampleDefaultValues establishes that explicit sample durations override header defaults. MediaSegment.CommonSampleDuration propagates the fragment lookup's result or error.

Stored property prop_08npczv97c found a counterexample with native Go fuzzing. Its deterministic checkProperty rerun at revision 702346275b141f91c229e5a759822d70d883d55c exited 1 using `go test ./mp4 -run '^FuzzPerfloopFragmentEffectiveDuration$' -count=1 -timeout=60s -v`. Retained reduced inputs show that one explicit target sample of duration 1 is rejected when either header supplies fallback 2. Another retained input has two nonempty target runs with effective durations [1,0], yet the lookup returns (1,nil). A separate fresh DecodeFile/GetFullSamples call agrees with the independent duration model in each case. The original returned corpus is retained too.

The independent Case should replay these inputs first, then check explicit and inherited runs in both orders, tfhd presence including zero, differing real durations, track selection and nil or absent-track errors. The confirming signal is agreement with effective sample durations without materializing defaults into the lookup's input. Property prop_k5h485zjw0 already passed its complete bounded read-only check over 256 fixtures and 3,072 calls; that is a regression control, not an unbounded proof. Confidence is medium.

The constructed CPU workload in receipt call_aYis8eoJp25lxCjfisyGHvSM repeatedly queries four-run, 240-sample fragments in explicit, inherited and override modes. Fragment.CommonSampleDuration accounts for 7.66 of 9.05 sampled CPU seconds in that combined workload. This measures neither consumer prevalence nor a saving. The override case exits after its first run, unlike the successful explicit case. The existing single-pass scan does not support a separate inefficient-algorithm finding.

The refreshed open implementation at https://github.com/Eyevinn/mp4ff/pull/657 changes AAC configuration parsing and descriptor construction, not duration folding. Prior finding hyp_h5pxyp6ckc concerns selecting the matching trex in streaming access; these failures already supply a matching trex and require a different repair.

Change to test: Keep the header fallback separate from the accumulated agreement between nonempty runs, so duration-presence flags alone determine inheritance. Preserve matching-track selection, rejection of zero or differing effective durations, and read-only behavior.

Where it lives

perfloop-oss/mp4ff

Evidence

The check fails before this change and passes with it: `For the bounded duration, header, run-shape and track-selection fixtures, Fragment.CommonSampleDuration and MediaSegment.CommonSampleDuration return the common nonzero effective duration using explicit sample durations before flagged tfhd defaults before trex defaults, ignore empty runs, reject zero or differing effective durations and fragments without samples, preserve nil and absent-track errors, and leave sample and header state unchanged across repeated calls.`

Checks: 6 of 6 passed. Verification: no defect found.

Timeline