Browse Source

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

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Previous version reviewed by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

(cherry picked from commit 7b5ff7d573)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
tags/n2.4.14
Michael Niedermayer 9 years ago
parent
commit
269ef77f2a
2 changed files with 15 additions and 7 deletions
  1. +14
    -6
      libavcodec/vp8.c
  2. +1
    -1
      libavcodec/vp8.h

+ 14
- 6
libavcodec/vp8.c View File

@@ -2263,7 +2263,7 @@ static void vp8_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *cur_frame,
#define update_pos(td, mb_y, mb_x) #define update_pos(td, mb_y, mb_x)
#endif #endif


static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr, int is_vp7) int jobnr, int threadnr, int is_vp7)
{ {
VP8Context *s = avctx->priv_data; VP8Context *s = avctx->priv_data;
@@ -2279,6 +2279,10 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void
curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize, curframe->tf.f->data[1] + 8 * mb_y * s->uvlinesize,
curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize curframe->tf.f->data[2] + 8 * mb_y * s->uvlinesize
}; };

if (c->end <= c->buffer && c->bits >= 0)
return AVERROR_INVALIDDATA;

if (mb_y == 0) if (mb_y == 0)
prev_td = td; prev_td = td;
else else
@@ -2382,18 +2386,19 @@ static av_always_inline void decode_mb_row_no_filter(AVCodecContext *avctx, void
update_pos(td, mb_y, mb_x); update_pos(td, mb_y, mb_x);
} }
} }
return 0;
} }


static void vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
static int vp7_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr) int jobnr, int threadnr)
{ {
decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 1);
} }


static void vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
static int vp8_decode_mb_row_no_filter(AVCodecContext *avctx, void *tdata,
int jobnr, int threadnr) int jobnr, int threadnr)
{ {
decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
return decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr, 0);
} }


static av_always_inline void filter_mb_row(AVCodecContext *avctx, void *tdata, static av_always_inline void filter_mb_row(AVCodecContext *avctx, void *tdata,
@@ -2476,13 +2481,16 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr,
VP8ThreadData *next_td = NULL, *prev_td = NULL; VP8ThreadData *next_td = NULL, *prev_td = NULL;
VP8Frame *curframe = s->curframe; VP8Frame *curframe = s->curframe;
int mb_y, num_jobs = s->num_jobs; int mb_y, num_jobs = s->num_jobs;
int ret;


td->thread_nr = threadnr; td->thread_nr = threadnr;
for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) { for (mb_y = jobnr; mb_y < s->mb_height; mb_y += num_jobs) {
if (mb_y >= s->mb_height) if (mb_y >= s->mb_height)
break; break;
td->thread_mb_pos = mb_y << 16; td->thread_mb_pos = mb_y << 16;
s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
ret = s->decode_mb_row_no_filter(avctx, tdata, jobnr, threadnr);
if (ret < 0)
return ret;
if (s->deblock_filter) if (s->deblock_filter)
s->filter_mb_row(avctx, tdata, jobnr, threadnr); s->filter_mb_row(avctx, tdata, jobnr, threadnr);
update_pos(td, mb_y, INT_MAX & 0xFFFF); update_pos(td, mb_y, INT_MAX & 0xFFFF);


+ 1
- 1
libavcodec/vp8.h View File

@@ -279,7 +279,7 @@ typedef struct VP8Context {
*/ */
int mb_layout; int mb_layout;


void (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
int (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
void (*filter_mb_row)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr); void (*filter_mb_row)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);


int vp7; int vp7;


Loading…
Cancel
Save