[FFmpeg-cvslog] avformat: Add max_streams option
Michael Niedermayer
git at videolan.org
Sun Dec 11 01:23:30 EET 2016
ffmpeg | branch: release/3.2 | Michael Niedermayer <michael at niedermayer.cc> | Fri Nov 18 17:00:30 2016 +0100| [3ecbac5664014f255b1eb0d81a36079d9bfc4f41] | committer: Michael Niedermayer
avformat: Add max_streams option
This allows user apps to stop OOM due to excessive number of streams
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 1296f844955e513d19051c962656f829479d4fb9)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ecbac5664014f255b1eb0d81a36079d9bfc4f41
---
doc/formats.texi | 4 ++++
libavformat/avformat.h | 7 +++++++
libavformat/options_table.h | 1 +
libavformat/utils.c | 2 +-
libavformat/version.h | 2 +-
5 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/doc/formats.texi b/doc/formats.texi
index 87704af..c51d408 100644
--- a/doc/formats.texi
+++ b/doc/formats.texi
@@ -209,6 +209,10 @@ For example to separate the fields with newlines and indention:
ffprobe -dump_separator "
" -i ~/videos/matrixbench_mpeg2.mpg
@end example
+
+ at 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
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index f9f4d72..c81a916 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -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);
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 9d61d5a..d5448e5 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -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},
};
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 5348e0d..20712bb 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4213,7 +4213,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)
diff --git a/libavformat/version.h b/libavformat/version.h
index 45c8334..ad25596 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 56
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list