return sign_extend(val, 5 + shift);
}
+#define check_scantable_index(ctx, x) \
+ do { \
+ if ((x) > 63) { \
+ av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
+ ctx->mb_x, ctx->mb_y); \
+ return AVERROR_INVALIDDATA; \
+ } \
+ } while (0) \
+
static inline int mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
{
int level, dc, diff, i, j, run;
break;
} else if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = (level * qscale * quant_matrix[j]) >> 4;
level = (level - 1) | 1;
level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
}
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = -level;
level = (level - 1) | 1;
}
}
- if (i > 63) {
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
block[j] = level;
}
if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
}
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = -level;
level = (level - 1) | 1;
}
}
- if (i > 63) {
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
block[j] = level;
if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = ((level * 2 + 1) * qscale) >> 1;
level = (level - 1) | 1;
level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
}
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = -level;
if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
}
}
- if (i > 63) {
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
mismatch ^= level;
block[j] = level;
if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = ((level * 2 + 1) * qscale) >> 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = ((-level * 2 + 1) * qscale) >> 1;
break;
} else if (level != 0) {
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
level = (level * qscale * quant_matrix[j]) >> 4;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
i += run;
+ check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = (-level * qscale * quant_matrix[j]) >> 4;
level = (level * qscale * quant_matrix[j]) >> 4;
}
}
- if (i > 63) {
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
mismatch ^= level;
block[j] = level;
static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, int16_t *block, int n)
{
- int level, dc, diff, j, run;
+ int level, dc, diff, i, j, run;
int component;
RLTable *rl;
- uint8_t * scantable = s->intra_scantable.permutated;
+ uint8_t * const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
const int qscale = s->qscale;
dc += diff;
s->last_dc[component] = dc;
block[0] = dc << (3 - s->intra_dc_precision);
+ i = 0;
if (s->intra_vlc_format)
rl = &ff_rl_mpeg2;
else
if (level == 127) {
break;
} else if (level != 0) {
- scantable += run;
- j = *scantable;
+ i += run;
+ check_scantable_index(s, i);
+ j = scantable[i];
level = (level * qscale * quant_matrix[j]) >> 4;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
- scantable += run;
- j = *scantable;
+ i += run;
+ check_scantable_index(s, i);
+ j = scantable[i];
if (level < 0) {
level = (-level * qscale * quant_matrix[j]) >> 4;
level = -level;
CLOSE_READER(re, &s->gb);
}
- s->block_last_index[n] = scantable - s->intra_scantable.permutated;
+ s->block_last_index[n] = i;
return 0;
}