Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling encrypted AAC frames when there's no encrypted data in a frame #4514

Merged
merged 1 commit into from
Feb 2, 2022

Conversation

loganek
Copy link
Contributor

@loganek loganek commented Jan 19, 2022

The decryptAacSample() was failing when the content size of the frame was
less than 16 bytes (which is the size of unencrypted portion). Specifically,
curUnit.set(decryptedData, 16); code was failing because curUnit
was smaller than 16, so there was attempt to write outside of the buffer.

According to the documentation [1], each AAC frame consists of

  • ADTS Header (7-9 bytes)
  • unencrypted leader (16 bytes)
  • a sequence of 16 bytes encrypted blocks (n x 16 bytes)
  • unencrypted trailer (0-15 bytes)

In the failing case, the frame contained ADTS header (7 bytes), but the
unencrypted leader was only 13 bytes long.

[1] Section 2.3.1.1 AAC https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption/Encryption/Encryption.html

This PR will fix...

handling AAC files with frames where unencrypted ladder is less than 16 bytes long

Why is this Pull Request needed?

To correctly handle edge cases

Are there any points in the code the reviewer needs to double check?

Resolves issues:

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

… frame

The `decryptAacSample()` was failing when the content size of the frame was
less than 16 bytes (which is the size of unencrypted portion). Specifically,
`curUnit.set(decryptedData, 16);` code was failing because `curUnit`
was smaller than 16, so there was attempt to write outside of the buffer.

According to the documentation [1], each AAC frame consists of
* ADTS Header (7-9 bytes)
* unencrypted leader (16 bytes)
* a sequence of 16 bytes encrypted blocks (n x 16 bytes)
* unencrypted trailer (0-15 bytes)

In the failing case, the frame contained ADTS header (7 bytes), but the
unencrypted leader was only 13 bytes long.

[1] Section `2.3.1.1 AAC` https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption/Encryption/Encryption.html
@robwalch robwalch added this to the 1.2.0 milestone Feb 2, 2022
@robwalch robwalch merged commit e466552 into video-dev:master Feb 2, 2022
littlespex pushed a commit to cbsinteractive/hls.js that referenced this pull request Dec 9, 2022
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.

2 participants