History

avcodec/vp8: Check for bitsteam end in decode_mb_row_no_filter()

Fixes timeout with 686/clusterfuzz-testcase-5853946876788736 this shortcuts (i.e. speeds up) the error and return-to-user when decoding a truncated frame

Michael Niedermayer committed 9 years ago

Commit 7b5ff7d1 parent 4bd3f1c2 files · +15 −7Browse files

Unified · Split

2 files
  1. libavcodec/vp8.c +14 −6
  2. libavcodec/vp8.h +1 −1
libavcodec/vp8.c+14−6
@@ -2275,7 +2275,7 @@ static void vp8_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *cur_frame, · 2274 unmodified lines
22752275 #define update_pos(td, mb_y, mb_x) while(0)
22762276 #endif
22772277
2278−static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2278+static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
22792279 int jobnr, int threadnr, int is_vp7)
22802280 {
22812281 VP8Context *s = avctx->priv_data;
@@ -2291,6 +2291,10 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void · 9 unmodified lines
22912291 curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize,
22922292 curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize
22932293 };
2294+
2295+ if (c->end <= c->buffer && c->bits >= 0)
2296+ return AVERROR_INVALIDDATA;
2297+
22942298 if (mb_y == 0)
22952299 prev_td = td;
22962300 else
@@ -2394,18 +2398,19 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void · 97 unmodified lines
23942398 update_pos(td, mb_y, mb_x);
23952399 }
23962400 }
2401+ return 0;
23972402 }
23982403
2399−static void vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2404+static int vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
24002405 int jobnr, int threadnr)
24012406 {
2402− decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
2407+ return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
24032408 }
24042409
2405−static void vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
2410+static int vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
24062411 int jobnr, int threadnr)
24072412 {
2408− decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
2413+ return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
24092414 }
24102415
24112416 static av_always_inline void filter_mb_row(AVCodecContext *avctx, void *tdata,
@@ -2488,13 +2493,16 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr, · 76 unmodified lines
24882493 VP8ThreadData *next_td = NULL, *prev_td = NULL;
24892494 VP8Frame *curframe = s->curframe;
24902495 int mb_y, num_jobs = s->num_jobs;
2496+ int ret;
24912497
24922498 td->thread_nr = threadnr;
24932499 for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
24942500 if (mb_y >= s->mb_height)
24952501 break;
24962502 td->thread_mb_pos = mb_y << 16;
2497− s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
2503+ ret = s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
2504+ if (ret < 0)
2505+ return ret;
24982506 if (s->deblock_filter)
24992507 s->filter_mb_row(avctx, tdata, jobnr, threadnr);
25002508 update_pos(td, mb_y, INT_MAX & 0xFFFF);
libavcodec/vp8.h+1−1
@@ -275,7 +275,7 @@ typedef struct VP8Context { · 274 unmodified lines
275275 */
276276 int mb_layout;
277277
278− void (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
278+ int (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
279279 void (*filter_mb_row)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
280280
281281 int vp7;

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