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

Bodecs Bela bodecsb at vivanet.hu
Thu Jun 20 10:46:29 EEST 2019


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

-------------- next part --------------
>From 902cae77b8f7f45634d949cba25bc82ff75653a8 Mon Sep 17 00:00:00 2001
From: Bela Bodecs <bodecsb at 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 at vivanet.hu>
---
 libavformat/hlsenc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

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);
-- 
2.20.1.windows.1



More information about the ffmpeg-devel mailing list