Commit 2ec66ff8 authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit 'cdbaa436'

* commit 'cdbaa436':
  mpeg12dec: Always close reader on error
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents c4ed2136 cdbaa436
......@@ -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;
}
......
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