Opened 2 years ago

Last modified 19 months ago

#9567 new defect

libavformat doesn't correctly decrypt video with hls sample-aes encryption

Reported by: haruka Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: hls
Cc: haruka Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:
The most obvious bug is in the function decrypt_video_frame in libavformat/hls_sample_encryption.c.

If encrypted NALU length is greater than decrypted, it means there were scep bytes removed so we need to move back the following NALUs. However, the memmove currently moves nothing and after shrinking the packet at the end, the last few bytes will get truncated and the resulting video stream will not be correctly decoded.

How to reproduce:
Trying to play some SAMPLE-AES encrypted TS streams using ffplay should be the easiest way to test it.
Apple has a test stream but it's walled behind Apple ID login (any Apple ID should be fine):

Attachments (1)

test.patch (1.1 KB ) - added by haruka 2 years ago.
Test patch

Download all attachments as: .zip

Change History (5)

by haruka, 2 years ago

Attachment: test.patch added

Test patch

comment:1 by haruka, 2 years ago

I've been tinkering with the code and this test patch (crude as I was just testing) could fix some of the decoding errors but not all of them.

comment:2 by Carl Eugen Hoyos, 19 months ago

Keywords: hls added

Please provide an ffmpeg command line that allows to reproduce the issue together with the complete, uncut console output to make this a valid ticket.

comment:3 by haruka, 19 months ago

Do you really need the exact ticket format to make this valid?

I think the description is pretty clear that the memory operations was having some issues; I have even pointed the exact function that contributes to it.

SAMPLE-AES encrypted videos which are not behind some proprietary protections are pretty rare, so I've pointed out where you could get a copy of example from apple's website. Unfortunately I don't have publicly available examples as the videos I have are private assets.

comment:4 by Balling, 19 months ago

Yes, he does.

Note: See TracTickets for help on using tickets.