summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/eatgq.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index 1308c07cff..46bf226f6a 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -58,7 +58,7 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx)
return 0;
}
-static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
+static int tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
{
uint8_t *perm = s->scantable.permutated;
int i, j, value;
@@ -66,6 +66,8 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb
for (i = 1; i < 64;) {
switch (show_bits(gb, 3)) {
case 4:
+ if (i >= 63)
+ return AVERROR_INVALIDDATA;
block[perm[i++]] = 0;
case 0:
block[perm[i++]] = 0;
@@ -75,6 +77,8 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb
case 1:
skip_bits(gb, 2);
value = get_bits(gb, 6);
+ if (value > 64 - i)
+ return AVERROR_INVALIDDATA;
for (j = 0; j < value; j++)
block[perm[i++]] = 0;
break;
@@ -102,6 +106,7 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb
}
}
block[0] += 128 << 4;
+ return 0;
}
static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], AVFrame *frame,
@@ -161,8 +166,11 @@ static int tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
if (ret < 0)
return ret;
- for (i = 0; i < 6; i++)
- tgq_decode_block(s, s->block[i], &gb);
+ for (i = 0; i < 6; i++) {
+ int ret = tgq_decode_block(s, s->block[i], &gb);
+ if (ret < 0)
+ return ret;
+ }
tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
bytestream2_skip(&s->gb, mode);
} else {