Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY
@ 2022-04-12  8:27 Zhao Zhili
  2022-04-12  8:32 ` Steven Liu
  2022-04-13 11:53 ` Anton Khirnov
  0 siblings, 2 replies; 5+ messages in thread
From: Zhao Zhili @ 2022-04-12  8:27 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY
  2022-04-12  8:27 [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY Zhao Zhili
@ 2022-04-12  8:32 ` Steven Liu
  2022-04-13 11:53 ` Anton Khirnov
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Liu @ 2022-04-12  8:32 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Zhao Zhili

Zhao Zhili <quinkblack@foxmail.com> 于2022年4月12日周二 16:28写道:
>
> 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
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

LGTM


Thanks
Steven
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY
  2022-04-12  8:27 [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY Zhao Zhili
  2022-04-12  8:32 ` Steven Liu
@ 2022-04-13 11:53 ` Anton Khirnov
  2022-04-13 12:32   ` "zhilizhao(赵志立)"
  2022-04-13 13:02   ` [FFmpeg-devel] [PATCH v2] " Zhao Zhili
  1 sibling, 2 replies; 5+ messages in thread
From: Anton Khirnov @ 2022-04-13 11:53 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Zhao Zhili

Quoting Zhao Zhili (2022-04-12 10:27:50)
> 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?

I would say return error, unless there are known buggy producers of
incomplete IVs that we want to support.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY
  2022-04-13 11:53 ` Anton Khirnov
@ 2022-04-13 12:32   ` "zhilizhao(赵志立)"
  2022-04-13 13:02   ` [FFmpeg-devel] [PATCH v2] " Zhao Zhili
  1 sibling, 0 replies; 5+ messages in thread
From: "zhilizhao(赵志立)" @ 2022-04-13 12:32 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



> On Apr 13, 2022, at 7:53 PM, Anton Khirnov <anton@khirnov.net> wrote:
> 
> Quoting Zhao Zhili (2022-04-12 10:27:50)
>> 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?
> 
> I would say return error, unless there are known buggy producers of
> incomplete IVs that we want to support.

Make sense. Actually it’s a story about shoot myself in the foot. I
created a buggy manifest, and the bug is hidden by the default
padding on the tail. So the vide only works with ffmpeg/ffplay. Let’s
hope I’m the only one make such mistake.

Will send a patch to return error in this case.

> 
> -- 
> Anton Khirnov
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH v2] avformat/hls: check IV size inside EXT-X-KEY
  2022-04-13 11:53 ` Anton Khirnov
  2022-04-13 12:32   ` "zhilizhao(赵志立)"
@ 2022-04-13 13:02   ` Zhao Zhili
  1 sibling, 0 replies; 5+ messages in thread
From: Zhao Zhili @ 2022-04-13 13:02 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

Before the patch, an implicit padding on the right is applied for
incomplete IV in manifest. No padding is allowed for IV inside
EXT-X-KEY.
---
 libavformat/hls.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 83ff4cc607..312294f0c7 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -810,7 +810,12 @@ 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 != 16) {
+                    av_log(c->ctx, AV_LOG_ERROR, "Incomplete IV '%s'\n", info.iv);
+                    ret = AVERROR_INVALIDDATA;
+                    goto fail;
+                }
                 has_iv = 1;
             }
             av_strlcpy(key, info.uri, sizeof(key));
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-13 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  8:27 [FFmpeg-devel] [PATCH RFC] avformat/hls: check IV size inside EXT-X-KEY Zhao Zhili
2022-04-12  8:32 ` Steven Liu
2022-04-13 11:53 ` Anton Khirnov
2022-04-13 12:32   ` "zhilizhao(赵志立)"
2022-04-13 13:02   ` [FFmpeg-devel] [PATCH v2] " Zhao Zhili

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git