aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-15 20:54:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-07-03 16:14:47 +0200
commitde6d8e6fba0e516b61c42d2100fff8b1aabe25e9 (patch)
treedb5aea2b167f27e9a0e1a6711bfa7caea1c7b217
parent939cb37247f23d738893efdb9f58f62b7c87001c (diff)
downloadffmpeg-de6d8e6fba0e516b61c42d2100fff8b1aabe25e9.tar.gz
fftools/ffmpeg_opt: Check attachment filesize
The data of an attachment file is put into an AVCodecParameter's extradata. The corresponding size field has type int, yet there was no check for the size to fit into an int. As a consequence, it was possible to create extradata with negative size (by using a big enough max_alloc). Other errors were also possible: If SIZE_MAX < INT64_MAX (e.g. on 32bit systems) then the file size might be truncated before the allocation; and avio_read() takes an int, too, so one would not have read as much as one desired. Furthermore, the extradata is now padded as is required. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit 889ad93c8839e5ac1ec28bc8e1fea6df71b9bf80) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--ffmpeg_opt.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 56d6e2f101..e89afe958e 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -2300,12 +2300,14 @@ loop_end:
o->attachments[i]);
exit_program(1);
}
- if (!(attachment = av_malloc(len))) {
- av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\n",
+ if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
+ !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
+ av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
o->attachments[i]);
exit_program(1);
}
avio_read(pb, attachment, len);
+ memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
ost = new_attachment_stream(o, oc, -1);
ost->stream_copy = 0;