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

Bela Bodecs git at videolan.org
Sat Jun 22 13:27:11 EEST 2019


ffmpeg | branch: master | Bela Bodecs <bodecsb at vivanet.hu> | Wed Jun 19 10:25:36 2019 +0200| [1beeb3b877d00385c80b1750b45fa4f5e2d96301] | committer: Steven Liu

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 at vivanet.hu>
Reviewed-by: Steven Liu<lq at onvideo.cn>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1beeb3b877d00385c80b1750b45fa4f5e2d96301
---

 libavformat/hlsenc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index b4cb0364b4..f6330ec2d5 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1885,7 +1885,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;
@@ -1987,6 +1987,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);



More information about the ffmpeg-cvslog mailing list