Skip to content

fix(aac): check that the NewADTSHeader arguments fit the ADTS header, accept AAC Main - #690

Merged
tobbee merged 1 commit into
masterfrom
adts-header-checks
Nov 3, 2026
Merged

tobbee merged 1 commit into
masterfrom
adts-header-checks

Conversation

@tobbee

@tobbee tobbee commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

aac.NewADTSHeader now checks every argument against its field in adts_fixed_header (ISO/IEC 14496-3:2019 Table 1.A.6), instead of letting Encode silently truncate the value:

  • channelConfig must be at most 7, because channel_configuration has 3 bits. Today 13 is written as 5.
  • plLen must be at most 8184, because the 13-bit frame_length includes the 7-byte header. Today 8185 is written as frame length 0. A valid AAC frame never gets that large: the decoder input buffer is 6144 bits per channel, so channel configurations 1–7 give at most 6144 bytes.
  • objectType may also be AACMain (profile 0), which DecodeADTSHeader already returns as object type 1. This follows the AAC Main support of Implement Main profile and additional ASC support; add SetAACDescriptorFromConfig #657. HE-AAC is still rejected, since ADTS sends it as AAC-LC with implicit SBR signaling.

Encode is unchanged and writes the fields as they are; its doc comment now says so.

Replaces #689, which checked only the payload length.

Tests

TestNewADTSHeader is one table that tests each limit at its boundary values: payload 0, 4096, 8184 accepted and 8185, 65535 rejected; channel configurations 0, 7 accepted and 8 rejected; object types Main and LC accepted, 0 and HE-AAC rejected; and a sampling frequency without an index. Each accepted header is encoded and decoded again.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EagxH7ENAVwUPJWTRiw1wQ

… accept AAC Main

NewADTSHeader now checks every value against its field in adts_fixed_header (ISO/IEC 14496-3:2019 Table 1.A.6):

- channelConfig must be at most 7, since channel_configuration has 3 bits. Before, Encode silently wrote only the low 3 bits, so 13 became 5.
- plLen must be at most 8184, since frame_length has 13 bits and includes the 7-byte header. Before, Encode wrapped larger values, so 8185 gave frame length 0. A valid AAC frame stays below this anyway: the decoder input buffer is 6144 bits per channel, so channel configurations 1-7 give at most 6144 bytes.
- objectType may also be AAC Main, which the 2-bit profile field signals as 0 and which DecodeADTSHeader already returns as object type 1. HE-AAC is still rejected, since ADTS sends it as AAC-LC with implicit SBR signaling.

TestNewADTSHeader tests each limit at its boundary values, plus a middle value, and decodes every accepted header again. This replaces PR #689, which checked only the payload length and tested all 65,536 lengths at each sample rate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EagxH7ENAVwUPJWTRiw1wQ
@tobbee
tobbee merged commit 0e63820 into master Nov 3, 2026
10 checks passed
@tobbee
tobbee deleted the adts-header-checks branch November 3, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant