History

avcodec/eatgq: : Check index increments in tgq_decode_block()

Fixes: out of array access Fixes: 48567/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_EATGQ_fuzzer-6743211456724992

Michael Niedermayer committed 3 years ago

Commit e7755b41 parent 2378cbe1 file · +11 −3Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/eatgq.c+11−3
@@ -56,7 +56,7 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx) · 55 unmodified lines
5656 return 0;
5757 }
5858
59−static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
59+static int tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
6060 {
6161 const uint8_t *scantable = ff_zigzag_direct;
6262 int i, j, value;
@@ -64,6 +64,8 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb · 1 unmodified line
6464 for (i = 1; i < 64;) {
6565 switch (show_bits(gb, 3)) {
6666 case 4:
67+ if (i >= 63)
68+ return AVERROR_INVALIDDATA;
6769 block[scantable[i++]] = 0;
6870 case 0:
6971 block[scantable[i++]] = 0;
@@ -73,6 +75,8 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb · 3 unmodified lines
7375 case 1:
7476 skip_bits(gb, 2);
7577 value = get_bits(gb, 6);
78+ if (value > 64 - i)
79+ return AVERROR_INVALIDDATA;
7680 for (j = 0; j < value; j++)
7781 block[scantable[i++]] = 0;
7882 break;
@@ -100,6 +104,7 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb · 21 unmodified lines
100104 }
101105 }
102106 block[0] += 128 << 4;
107+ return 0;
103108 }
104109
105110 static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], AVFrame *frame,
@@ -160,8 +165,11 @@ static int tgq_decode_mb(TgqContext *s, GetByteContext *gbyte, · 54 unmodified lines
160165 if (ret < 0)
161166 return ret;
162167
163− for (i = 0; i < 6; i++)
164− tgq_decode_block(s, s->block[i], &gb);
168+ for (i = 0; i < 6; i++) {
169+ int ret = tgq_decode_block(s, s->block[i], &gb);
170+ if (ret < 0)
171+ return ret;
172+ }
165173 tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
166174 bytestream2_skip(gbyte, mode);
167175 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t