Commit fa7dec8c authored by Andreas Cadhalpun's avatar Andreas Cadhalpun

nutdec: stop skipping bytes at EOF

This can unnecessarily waste a lot of time.
Reviewed-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
Signed-off-by: 's avatarAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
parent 37e67988
...@@ -47,6 +47,8 @@ static int get_str(AVIOContext *bc, char *string, unsigned int maxlen) ...@@ -47,6 +47,8 @@ static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
while (len > maxlen) { while (len > maxlen) {
avio_r8(bc); avio_r8(bc);
len--; len--;
if (bc->eof_reached)
len = maxlen;
} }
if (maxlen) if (maxlen)
...@@ -213,8 +215,11 @@ static int skip_reserved(AVIOContext *bc, int64_t pos) ...@@ -213,8 +215,11 @@ static int skip_reserved(AVIOContext *bc, int64_t pos)
avio_seek(bc, pos, SEEK_CUR); avio_seek(bc, pos, SEEK_CUR);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} else { } else {
while (pos--) while (pos--) {
if (bc->eof_reached)
return AVERROR_INVALIDDATA;
avio_r8(bc); avio_r8(bc);
}
return 0; return 0;
} }
} }
...@@ -293,8 +298,13 @@ static int decode_main_header(NUTContext *nut) ...@@ -293,8 +298,13 @@ static int decode_main_header(NUTContext *nut)
if (tmp_fields > 7) if (tmp_fields > 7)
tmp_head_idx = ffio_read_varlen(bc); 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); ffio_read_varlen(bc);
}
if (count <= 0 || count > 256 - (i <= 'N') - i) { if (count <= 0 || count > 256 - (i <= 'N') - i) {
av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i); av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i);
...@@ -992,8 +1002,13 @@ static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, ...@@ -992,8 +1002,13 @@ static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
*header_idx = ffio_read_varlen(bc); *header_idx = ffio_read_varlen(bc);
if (flags & FLAG_RESERVED) if (flags & FLAG_RESERVED)
reserved_count = ffio_read_varlen(bc); 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); ffio_read_varlen(bc);
}
if (*header_idx >= (unsigned)nut->header_count) { if (*header_idx >= (unsigned)nut->header_count) {
av_log(s, AV_LOG_ERROR, "header_idx invalid\n"); av_log(s, AV_LOG_ERROR, "header_idx invalid\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment