Timecode calculation wraps valid elapsed track time

perfloop-oss/mp4ff · Numeric Representation Loss

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

Verdict

VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-12

What happened: The check passes with this change.

Hypothesis

GetTimeCode can return a near-zero time after elapsed track-time units exceed the 32-bit range, although the correct time fits its return type. This concerns the documented exported library operation; an internal caller or production occurrence was not established. It is a medium-confidence correctness lead.

GetTimeCode stores elapsed units in uint32 and multiplies sample counts and deltas in uint32 before converting to time.Duration. Both the product and accumulated sum can therefore lose required information. The documented result is elapsed time to the start of the sample, not a wrapping counter.

checkProperty(prop_0w5cec0px1) found a failure after 2324 fuzz executions at revision 702346275b141f91c229e5a759822d70d883d55c. The stored check encodes and decodes a timing table and compares the public operation with independent integer arithmetic whose numerator and result cannot overflow within its stated bounds. The returned replay produces 2.666666ms instead of 24h51m18.488s. A normalized replay uses one run covering three samples, delta 2147483648, sample 3 and timescale 48000. Its 4294967296 elapsed ticks become 0s instead of 24h51m18.485333333s. The deterministic command go test ./mp4 -run '^FuzzPerfloopSttsTimeCode$' -count=1 -v reproduces both stored failures; ordinary and just-below-wrap control seeds pass.

A Case should reproduce the retained inputs and compare with an exact integer reference on both sides of the accumulated-unit boundary. It must also protect against overflow introduced during the conversion to nanoseconds when widening the accumulator. Preserve ordinary values and fractional-nanosecond truncation, limiting the assurance claim to covered indices, positive timescales and results representable by time.Duration. The operation can retain its linear run traversal without a cache or new public API.

The refreshed open-work listing and actual implementation review of https://github.com/Eyevinn/mp4ff/pull/657 showed AAC configuration changes, not timecode arithmetic.

Change to test: Accumulate elapsed track-time units in a wide integer and convert with overflow-safe arithmetic. Preserve nanosecond truncation for representable results, existing indexing behavior and the public signature.

Where it lives

perfloop-oss/mp4ff

Evidence

The check passes with this change: `For the pinned FFmpeg MP4 containing 50400 samples with sample delta and timescale 90000, decoded through mp4.DecodeFile, SttsBox.GetTimeCode returns exact elapsed sample-start time at sample 47722 but returns the uint32-wrapped value instead of exact elapsed time at samples 47723 and 50400.`

Verification: no defect found.

Timeline