]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL
authorMichael Niedermayer <michael@niedermayer.cc>
Sun, 26 Jul 2020 17:41:30 +0000 (19:41 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Tue, 28 Jul 2020 19:57:50 +0000 (21:57 +0200)
Fixes: division by zero
Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Gautam Ramakrishnan <gautamramk@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/jpeg2000dec.c

index a470cf47dabfaff061e475359b3caa5290cef725..b168e52db6ca54d2822942c7e9099a1cfdad8152 100644 (file)
@@ -1401,12 +1401,12 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
                         if (!s->cdx[compno] || !s->cdy[compno])
                             return AVERROR_INVALIDDATA;
 
-                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
-                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
-
                         if (reslevelno >= codsty->nreslevels)
                             continue;
 
+                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
+                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
+
                         if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
                              (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
                             continue;