[FFmpeg-cvslog] avformat/hls: Fix DoS due to infinite loop

Michael Niedermayer git at videolan.org
Sat Sep 2 03:30:20 EEST 2017


ffmpeg | branch: release/2.8 | Michael Niedermayer <michael at niedermayer.cc> | Sat Aug 26 01:26:58 2017 +0200| [498e07daa18cca6115eb415e592cde3701a2b800] | committer: Michael Niedermayer

avformat/hls: Fix DoS due to infinite loop

Fixes: loop.m3u

The default max iteration count of 1000 is arbitrary and ideas for a better solution are welcome

Found-by: Xiaohei and Wangchu from Alibaba Security Team

Previous version reviewed-by: Steven Liu <lingjiujianke at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 7ec414892ddcad88313848494b6fc5f437c9ca4a)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 doc/demuxers.texi | 18 ++++++++++++++++++
 libavformat/hls.c |  7 +++++++
 2 files changed, 25 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 99b221c4b4..9cef8877a9 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -283,6 +283,24 @@ used to end the output video at the length of the shortest input file,
 which in this case is @file{input.mp4} as the GIF in this example loops
 infinitely.
 
+ at section hls
+
+HLS demuxer
+
+It accepts the following options:
+
+ at table @option
+ at item live_start_index
+segment index to start live streams at (negative values are from the end).
+
+ at item allowed_extensions
+',' separated list of file extensions that hls is allowed to access.
+
+ at item max_reload
+Maximum number of times a insufficient list is attempted to be reloaded.
+Default value is 1000.
+ at end table
+
 @section image2
 
 Image file demuxer.
diff --git a/libavformat/hls.c b/libavformat/hls.c
index 677421fce5..bccaf67fa1 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -198,6 +198,7 @@ typedef struct HLSContext {
     char *headers;                       ///< holds HTTP headers set as an AVOption to the HTTP protocol context
     AVDictionary *avio_opts;
     char *allowed_extensions;
+    int max_reload;
 } HLSContext;
 
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
@@ -1252,6 +1253,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
     HLSContext *c = v->parent->priv_data;
     int ret, i;
     int just_opened = 0;
+    int reload_count = 0;
 
 restart:
     if (!v->needed)
@@ -1283,6 +1285,9 @@ restart:
         reload_interval = default_reload_interval(v);
 
 reload:
+        reload_count++;
+        if (reload_count > c->max_reload)
+            return AVERROR_EOF;
         if (!v->finished &&
             av_gettime_relative() - v->last_load_time >= reload_interval) {
             if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) {
@@ -2011,6 +2016,8 @@ static const AVOption hls_options[] = {
         OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
         {.str = "3gp,aac,avi,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"},
         INT_MIN, INT_MAX, FLAGS},
+    {"max_reload", "Maximum number of times a insufficient list is attempted to be reloaded",
+        OFFSET(max_reload), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, FLAGS},
     {NULL}
 };
 



More information about the ffmpeg-cvslog mailing list