diff mbox

[FFmpeg-devel] avformat/hlsenc: better checking var_stream_map content

Message ID 2dafb4ba-7f84-fbd9-3a24-e624945c6293@vivanet.hu
State Accepted
Commit 1beeb3b877d00385c80b1750b45fa4f5e2d96301
Headers show

Commit Message

Bodecs Bela June 20, 2019, 7:46 a.m. UTC
Dear All,

When multiple variant streams are specified by var_stream_map option,
implementation assumes that each elementary stream is assigned only once
to any variant. But this is not checked currently. But 2nd and further 
instances
of same elementary source streams are silently neglected without any notice.
Examples for invalid var_stream_map content:
"v:0,a:0 v:1,a:0"
This is invalid because 1st and 2nd variant also contains a:0 source

"v:0,a:0,v:0 v:1,a:1"
This is invalid because 1st variant source contains v:0 twice.

This patch makes this checking early, during the var_stream_map parsing 
phase.

please review this patch.

best

Bela
From 902cae77b8f7f45634d949cba25bc82ff75653a8 Mon Sep 17 00:00:00 2001
From: Bela Bodecs <bodecsb@vivanet.hu>
Date: Wed, 19 Jun 2019 10:25:36 +0200
Subject: [PATCH] avformat/hlsenc: better checking var_stream_map content

When multiple variant streams are specified by var_stream_map option,
implementation assumes that each elementary stream is assigned only once
to any variant. But this is not checked. This patch makes this checking.


Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
---
 libavformat/hlsenc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Liu Steven June 22, 2019, 10:27 a.m. UTC | #1
> 在 2019年6月20日,15:46,Bodecs Bela <bodecsb@vivanet.hu> 写道:
> 
> Dear All,
> 
> When multiple variant streams are specified by var_stream_map option,
> implementation assumes that each elementary stream is assigned only once
> to any variant. But this is not checked currently. But 2nd and further instances
> of same elementary source streams are silently neglected without any notice.
> Examples for invalid var_stream_map content:
> "v:0,a:0 v:1,a:0"
> This is invalid because 1st and 2nd variant also contains a:0 source
> 
> "v:0,a:0,v:0 v:1,a:1"
> This is invalid because 1st variant source contains v:0 twice.
> 
> This patch makes this checking early, during the var_stream_map parsing phase.
> 
> please review this patch.
> 
> best
> 
> Bela
> 
> <0001-avformat-hlsenc-better-checking-var_stream_map-conte.patch>_______________________________________________
> 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”.

Applied!


Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f88b8a9618..77f84dd547 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1887,7 +1887,7 @@  static int parse_variant_stream_mapstring(AVFormatContext *s)
 {
     HLSContext *hls = s->priv_data;
     VariantStream *vs;
-    int stream_index;
+    int stream_index, i, j;
     enum AVMediaType codec_type;
     int nb_varstreams, nb_streams;
     char *p, *q, *saveptr1, *saveptr2, *varstr, *keyval;
@@ -1989,6 +1989,23 @@  static int parse_variant_stream_mapstring(AVFormatContext *s)
                                                            atoi(val));
 
             if (stream_index >= 0 && nb_streams < vs->nb_streams) {
+                for(i = 0; nb_streams > 0 && i < nb_streams; i++) {
+                    if (vs->streams[i] == s->streams[stream_index]) {
+                        av_log(s, AV_LOG_ERROR, "Same elementary stream found more than once inside "
+                               "variant definition #%d\n", nb_varstreams - 1);
+                        return AVERROR(EINVAL);
+                    }
+                }
+                for(j = 0; nb_varstreams > 1 && j < nb_varstreams - 1; j++) {
+                    for(i = 0; i < hls->var_streams[j].nb_streams; i++) {
+                        if (hls->var_streams[j].streams[i] == s->streams[stream_index]) {
+                            av_log(s, AV_LOG_ERROR, "Same elementary stream found more than once "
+                                   "in two different variant definitions #%d and #%d\n",
+                                   j, nb_varstreams - 1);
+                            return AVERROR(EINVAL);
+                        }
+                    }
+                }
                 vs->streams[nb_streams++] = s->streams[stream_index];
             } else {
                 av_log(s, AV_LOG_ERROR, "Unable to map stream at %s\n", keyval);