]> git.sesse.net Git - ffmpeg/commitdiff
avformat: Add max_streams option
authorMichael Niedermayer <michael@niedermayer.cc>
Fri, 18 Nov 2016 16:00:30 +0000 (17:00 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 8 Dec 2016 17:25:30 +0000 (18:25 +0100)
This allows user apps to stop OOM due to excessive number of streams

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
doc/formats.texi
libavformat/avformat.h
libavformat/options_table.h
libavformat/utils.c
libavformat/version.h

index 87704afb6c00d5a2c99ae3b5ce2d6a6aa6ae4b36..c51d4086db596d5f806744684285f49723581936 100644 (file)
@@ -209,6 +209,10 @@ For example to separate the fields with newlines and indention:
 ffprobe -dump_separator "
                           "  -i ~/videos/matrixbench_mpeg2.mpg
 @end example
+
+@item max_streams @var{integer} (@emph{input})
+Specifies the maximum number of streams. This can be used to reject files that
+would require too many resources due to a large number of streams.
 @end table
 
 @c man end FORMAT OPTIONS
index adf08d7c9167a0baecf12f0f99a0441478a0897c..af257e43c4e5cd88152282f1d33d630153c5f055 100644 (file)
@@ -1899,6 +1899,13 @@ typedef struct AVFormatContext {
      * - decoding: set by user through AVOptions (NO direct access)
      */
     char *protocol_blacklist;
+
+    /**
+     * The maximum number of streams.
+     * - encoding: unused
+     * - decoding: set by user through AVOptions (NO direct access)
+     */
+    int max_streams;
 } AVFormatContext;
 
 int av_format_get_probe_score(const AVFormatContext *s);
index 9d61d5a158b2688efd8884629d757b97ba6b5be9..d5448e503f5471e4db1587b583ccf707937d4be5 100644 (file)
@@ -105,6 +105,7 @@ static const AVOption avformat_options[] = {
 {"format_whitelist", "List of demuxers that are allowed to be used", OFFSET(format_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  CHAR_MIN, CHAR_MAX, D },
 {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  CHAR_MIN, CHAR_MAX, D },
 {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  CHAR_MIN, CHAR_MAX, D },
+{"max_streams", "maximum number of streams", OFFSET(max_streams), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, D },
 {NULL},
 };
 
index 5f69b6bce94e73839490dc29046b4b1dfd900956..9e979a7c79543ddf0ea095e387163b4cd4e83a07 100644 (file)
@@ -4217,7 +4217,7 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
     int i;
     AVStream **streams;
 
-    if (s->nb_streams >= INT_MAX/sizeof(*streams))
+    if (s->nb_streams >= FFMIN(s->max_streams, INT_MAX/sizeof(*streams)))
         return NULL;
     streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
     if (!streams)
index a42d5800d740ed295f2fe75b0defc4d7b0d107c1..192b790ba46753786985bf359bc1c95ec8c3baf2 100644 (file)
@@ -32,8 +32,8 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
-#define LIBAVFORMAT_VERSION_MINOR  58
-#define LIBAVFORMAT_VERSION_MICRO 102
+#define LIBAVFORMAT_VERSION_MINOR  59
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \