aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-05-20 00:31:24 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-06-10 02:13:12 +0200
commitb6ae28c2e9cb1b667a4fd51feb9ad63987c0c9c2 (patch)
tree85a287394716a72dfecc82707e553156d9d4b70e /libavformat
parent5123c8aa0bf35c0340f0562986440b654ed7bb8c (diff)
downloadffmpeg-b6ae28c2e9cb1b667a4fd51feb9ad63987c0c9c2.tar.gz
nutdec: stop skipping bytes at EOF
This can unnecessarily waste a lot of time. Reviewed-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> (cherry picked from commit fa7dec8cb00d2d0dd96ff9863ccda38428610a21) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/nutdec.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 6b93bec7d5..08f070a652 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -44,6 +44,8 @@ static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
while (len > maxlen) {
avio_r8(bc);
len--;
+ if (bc->eof_reached)
+ len = maxlen;
}
if (maxlen)
@@ -210,8 +212,11 @@ static int skip_reserved(AVIOContext *bc, int64_t pos)
avio_seek(bc, pos, SEEK_CUR);
return AVERROR_INVALIDDATA;
} else {
- while (pos--)
+ while (pos--) {
+ if (bc->eof_reached)
+ return AVERROR_INVALIDDATA;
avio_r8(bc);
+ }
return 0;
}
}
@@ -285,8 +290,13 @@ static int decode_main_header(NUTContext *nut)
if (tmp_fields > 7)
tmp_head_idx = ffio_read_varlen(bc);
- while (tmp_fields-- > 8)
+ while (tmp_fields-- > 8) {
+ if (bc->eof_reached) {
+ av_log(s, AV_LOG_ERROR, "reached EOF while decoding main header\n");
+ return AVERROR_INVALIDDATA;
+ }
ffio_read_varlen(bc);
+ }
if (count <= 0 || count > 256 - (i <= 'N') - i) {
av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
@@ -825,8 +835,13 @@ static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
*header_idx = ffio_read_varlen(bc);
if (flags & FLAG_RESERVED)
reserved_count = ffio_read_varlen(bc);
- for (i = 0; i < reserved_count; i++)
+ for (i = 0; i < reserved_count; i++) {
+ if (bc->eof_reached) {
+ av_log(s, AV_LOG_ERROR, "reached EOF while decoding frame header\n");
+ return AVERROR_INVALIDDATA;
+ }
ffio_read_varlen(bc);
+ }
if (*header_idx >= (unsigned)nut->header_count) {
av_log(s, AV_LOG_ERROR, "header_idx invalid\n");