avcodec/jpeg2000dec: Fix division by zero in jp2_find_codestream()
authorMichael Niedermayer <michael@niedermayer.cc>
Mon, 24 Jul 2017 14:43:24 +0000 (16:43 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 26 Jul 2017 15:06:29 +0000 (17:06 +0200)
Fixes: 2707/clusterfuzz-testcase-minimized-5179636394754048

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/jpeg2000dec.c

index b67efc7..dd9c60f 100644 (file)
@@ -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;