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

sample-aes decryption with nals <= 48 corrupts AVC bitstream, fix included #3102

Closed
arturpilaszkiewicz opened this issue Oct 14, 2020 · 0 comments
Labels
Milestone

Comments

@arturpilaszkiewicz
Copy link

arturpilaszkiewicz commented Oct 14, 2020

What version of Hls.js are you using?

master@e1fc9696458a11480b6a75ca852d273a8c5029ae

What browser and OS are you using?

any

Test stream:

https://r.dcs.dev.redlabs.pl/vod/hls/o2/ATM-Lab/zos/test/8c4627321de9e21be017675f68a319e2/00003.ism/playlist.m3u8
works ok on safari + native playback

Description:

Nals <= 48 go through decryption phase
Nothing is decrypted (too few data), but discardEPB is performed, which corrupts bitstream, which results

  • in artifacts in playback,
  • depending on target machine + browser this may also freeze the tab/browser, as corrupt data is fed to decoder

This error looks like a typo.

fix:

diff --git a/src/demux/sample-aes.js b/src/demux/sample-aes.js
index 47a96544..3a3c443b 100644
--- a/src/demux/sample-aes.js
+++ b/src/demux/sample-aes.js
@@ -100,17 +100,18 @@ class SampleAesDecrypter {
 
       let curUnits = samples[sampleIndex].units;
       for (;; unitIndex++) {
         if (unitIndex >= curUnits.length) {
           break;
         }
 
         let curUnit = curUnits[unitIndex];
-        if (curUnit.length <= 48 || (curUnit.type !== 1 && curUnit.type !== 5)) {
+        // hls.js fix, currUnit.length does not exist, currUnit.data.length does exist
+        if (curUnit.data.length <= 48 || (curUnit.type !== 1 && curUnit.type !== 5)) {
           continue;
         }
 
         let sync = this.decrypter.isSync();
 
         this.decryptAvcSample(samples, sampleIndex, unitIndex, callback, curUnit, sync);
 
         if (!sync) {

reference:
https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption/Encryption/Encryption.html

kuczek pushed a commit to kuczek/hls.js that referenced this issue Oct 19, 2020
kuczek pushed a commit to kuczek/hls.js that referenced this issue Oct 19, 2020
robwalch added a commit that referenced this issue Oct 19, 2020
…n-problem

Sample AES decryption with 48 AVC Closes: #3102
@robwalch robwalch added the Bug label Oct 19, 2020
@robwalch robwalch added this to the 0.14.16 milestone Oct 19, 2020
robwalch pushed a commit that referenced this issue Oct 19, 2020
robwalch pushed a commit that referenced this issue Oct 19, 2020
* patch/v0.14.x:
  when audio level loaded, check if we already know that it's live
  on level load, check current level details as well as new when determining live-ness
  Sample AES decryption with 48 AVC Closes: #3102
kuczek pushed a commit to kuczek/hls.js that referenced this issue Oct 19, 2020
kuczek pushed a commit to kuczek/hls.js that referenced this issue Oct 19, 2020
robwalch pushed a commit that referenced this issue Oct 20, 2020
* master: (29 commits)
  when audio level loaded, check if we already know that it's live
  on level load, check current level details as well as new when determining live-ness
  Sample AES decryption with 48 AVC Closes: #3102
  when audio level loaded, check if we already know that it's live
  chore(deps): Upgrading TypeScript to 4.0.3.
  Sample AES decryption with 48 AVC Closes: #3102
  Bump chart.js from 2.9.3 to 2.9.4
  Bump url-toolkit from 2.2.0 to 2.2.1
  Bump mocha from 8.1.3 to 8.2.0
  Bump @babel/core from 7.12.1 to 7.12.3
  Bump @babel/helper-module-imports from 7.10.4 to 7.12.1
  Bump @babel/plugin-proposal-class-properties from 7.10.4 to 7.12.1
  Bump @types/chai from 4.2.13 to 4.2.14
  Bump @babel/plugin-proposal-object-rest-spread from 7.11.0 to 7.12.1
  on level load, check current level details as well as new when determining live-ness
  Bump @babel/plugin-transform-object-assign from 7.10.4 to 7.12.1
  Bump @babel/core from 7.11.6 to 7.12.1
  Bump @babel/preset-typescript from 7.10.4 to 7.12.1
  Bump @babel/preset-env from 7.11.5 to 7.12.1
  Bump @babel/register from 7.11.5 to 7.12.1
  ...

# Conflicts:
#	.eslintrc.js
#	package-lock.json
#	package.json
#	src/config.ts
#	src/controller/audio-stream-controller.js
#	src/controller/buffer-controller.ts
#	src/controller/fragment-finders.ts
#	src/controller/stream-controller.js
#	src/controller/timeline-controller.ts
#	src/demux/sample-aes.js
#	src/loader/fragment.ts
#	src/loader/m3u8-parser.ts
#	src/remux/mp4-remuxer.ts
#	src/types/track.ts
#	src/utils/timescale-conversion.ts
#	tests/.eslintrc.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants