[FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY

Zhao Zhili quinkblack at foxmail.com
Tue Apr 12 11:27:50 EEST 2022


IV should always be 128 bits. If the IV attribute was truncated
inside EXT-X-KEY, padding on the left which is the same as when
using sequence number as IV.
---
I'm not sure which method is better: do padding or just return
AVERROR_INVALIDDATA?

 libavformat/hls.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 83ff4cc607..a7b632c20e 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -810,7 +810,13 @@ static int parse_playlist(HLSContext *c, const char *url,
             if (!strcmp(info.method, "SAMPLE-AES"))
                 key_type = KEY_SAMPLE_AES;
             if (!av_strncasecmp(info.iv, "0x", 2)) {
-                ff_hex_to_data(iv, info.iv + 2);
+                int n = ff_hex_to_data(iv, info.iv + 2);
+                if (n < sizeof(iv)) {
+                    av_log(c->ctx, AV_LOG_WARNING,
+                           "Incomplete IV %s, padding on the left\n", info.iv);
+                    memmove(iv + sizeof(iv) - n, iv, n);
+                    memset(iv, 0, sizeof(iv) - n);
+                }
                 has_iv = 1;
             }
             av_strlcpy(key, info.uri, sizeof(key));
-- 
2.31.1



More information about the ffmpeg-devel mailing list