Reject payload lengths that overflow the ADTS frame field
perfloop-oss/mp4ff · Numeric Representation Loss
https://perfloop.ai/t/oss/case_f2b5ezjz17
Verdict
VERIFIED · settled 2026-11-03
What happened: The check fails before this change and passes with it.
Hypothesis
The ADTS constructor accepts payload lengths that cannot fit the encoded frame length. Encoding silently reduces the requested length, so a caller can receive success before emitting a wrong or undecodable header. The frequency of these library inputs and downstream impact are unknown.
NewADTSHeader stores an unrestricted uint16 payload length. ADTSHeader.Encode adds its seven-byte header and writes only thirteen frame-length bits. bits.Writer.Write masks to that width. The smallest unrepresentable payload is 8185: its required total is 8192, but the emitted frame_length is zero. Larger uint16 inputs can also wrap in the addition before the same bit-field reduction. A guard at the existing fallible constructor can remove this whole unrepresentable range.
The failing checkProperty run for prop_chxe6yqs0m at revision 702346275b141f91c229e5a759822d70d883d55c completely enumerated all 65,536 uint16 payload values at 48,000 Hz, AAC-LC and stereo. It found 57,351 encoded-length mismatches, starting at payload 8185. Payloads 0 through 8184 passed independent wide-arithmetic wire checks and successful decoding. The check's separate channel axis is not evidence for this payload-only repair. Its command is `go test ./aac -run '^TestPerfloopADTSConstructorWireFit$' -count=1 -timeout=60s -v`. For wrong wire lengths the checker returns before decoding, so this count does not assert that every malformed result decoded successfully.
The independent Case proof target is a constructor error for lengths above 8184, a deterministic 8185 replay, and exact accepted round trips including payloads 0 and 8184. This is a header-only representation property; actual AAC payload contents and direct mutation of returned headers are outside scope. The additional complexity is one constant-time range guard and no dependency. Newly rejecting previously accepted, unrepresentable lengths is an intentional behavior change requiring release documentation. Confidence is medium.
The open-PR list was refreshed before publication. https://github.com/Eyevinn/mp4ff/pull/657 changes AudioSpecificConfig parsing and validation, not this ADTS constructor or thirteen-bit frame length; its actual changed-file implementation was compared. Its linked c94c23a implementation remains unavailable, an evidence gap. The existing short-frame decoder guard at aac/adts.go:122-124 rejects some malformed results later but does not prevent construction success or wrong encoded bytes.
Change to test: Reject payload lengths above 8184 in NewADTSHeader so the seven-byte-header frame length always fits its thirteen-bit wire field. Preserve all currently supported rates, AAC-LC and exact payload lengths 0 through 8184, without adding AAC payload parsing or changing direct-struct encoding semantics.
Where it lives
Evidence
The check fails before this change and passes with it: `For AAC-LC stereo at every built-in supported sampling frequency, NewADTSHeader rejects every uint16 payload length above 8184 with a nil header and an error; lengths 0 through 8184 encode an exact payload-plus-seven frame length and round-trip through DecodeADTSHeader unchanged at offset zero.`
Checks: 3 of 3 passed. Verification: no defect found.