diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index b67efc76bb..dd9c60feb4 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2075,6 +2075,11 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) hden = bytestream2_get_be16u(&s->g); vexp = bytestream2_get_byteu(&s->g); hexp = bytestream2_get_byteu(&s->g); + if (!vnum || !vden || !hnum || !vden) { + bytestream2_seek(&s->g, atom2_end, SEEK_SET); + av_log(s->avctx, AV_LOG_WARNING, "RES box invalid\n"); + continue; + } if (vexp > hexp) { vexp -= hexp; hexp = 0;