diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-16 18:57:41 +0000 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-16 19:01:05 +0000 |
commit | 2ec66ff83d00c3dbef06616e86994bb33d319202 (patch) | |
tree | 7818b54771590bc1a35e3a00fc512853bcf1dedd /libavcodec/mpeg12dec.c | |
parent | c4ed21367559ec56a5e2d5197f930a871a86a510 (diff) | |
parent | cdbaa436042ba59c3b2bd7e9652e9a14136fd604 (diff) | |
download | ffmpeg-2ec66ff83d00c3dbef06616e86994bb33d319202.tar.gz |
Merge commit 'cdbaa436042ba59c3b2bd7e9652e9a14136fd604'
* commit 'cdbaa436042ba59c3b2bd7e9652e9a14136fd604':
mpeg12dec: Always close reader on error
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/mpeg12dec.c')
-rw-r--r-- | libavcodec/mpeg12dec.c | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index cc8ace8e3a..4e6e4a2133 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -124,9 +124,10 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) return sign_extend(val, 5 + shift); } +#define MAX_INDEX (64 - 1) #define check_scantable_index(ctx, x) \ do { \ - if ((x) > 63) { \ + if ((x) > MAX_INDEX) { \ av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \ ctx->mb_x, ctx->mb_y); \ return AVERROR_INVALIDDATA; \ @@ -167,7 +168,8 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, if (level != 0) { i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; level = (level * qscale * quant_matrix[j]) >> 4; level = (level - 1) | 1; @@ -189,7 +191,8 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, SKIP_BITS(re, &s->gb, 8); } i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = -level; @@ -212,6 +215,9 @@ end: LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); } + + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -253,7 +259,8 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, if (level != 0) { i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; level = (level - 1) | 1; @@ -275,7 +282,8 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, SKIP_BITS(re, &s->gb, 8); } i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = -level; @@ -297,6 +305,9 @@ end: LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); } + + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -338,7 +349,8 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, if (level != 0) { i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; level = ((level * 2 + 1) * qscale) >> 1; level = (level - 1) | 1; @@ -360,7 +372,8 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, SKIP_BITS(re, &s->gb, 8); } i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = -level; @@ -382,6 +395,9 @@ end: LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); } + + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -427,7 +443,8 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, if (level != 0) { i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - @@ -442,7 +459,8 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, SKIP_BITS(re, &s->gb, 12); i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5; @@ -464,6 +482,8 @@ end: } block[63] ^= (mismatch & 1); + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -502,6 +522,8 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, if (level != 0) { i += run; + if (i > MAX_INDEX) + break; j = scantable[i]; level = ((level * 2 + 1) * qscale) >> 1; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - @@ -516,6 +538,8 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, SKIP_BITS(re, &s->gb, 12); i += run; + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = ((-level * 2 + 1) * qscale) >> 1; @@ -534,6 +558,9 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, end: LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); + + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -584,7 +611,8 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, break; } else if (level != 0) { i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; level = (level * qscale * quant_matrix[j]) >> 4; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - @@ -598,7 +626,8 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); i += run; - check_scantable_index(s, i); + if (i > MAX_INDEX) + break; j = scantable[i]; if (level < 0) { level = (-level * qscale * quant_matrix[j]) >> 4; @@ -615,6 +644,8 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, } block[63] ^= mismatch & 1; + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } @@ -694,6 +725,8 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, CLOSE_READER(re, &s->gb); } + check_scantable_index(s, i); + s->block_last_index[n] = i; return 0; } |