opj_t1_encode_cblk(): avoid uint32 overflow when numbps = 0 (which is well defined...
authorEven Rouault <even.rouault@spatialys.com>
Wed, 16 Aug 2017 16:29:59 +0000 (18:29 +0200)
committerEven Rouault <even.rouault@spatialys.com>
Wed, 16 Aug 2017 16:29:59 +0000 (18:29 +0200)
src/lib/openjp2/t1.c

index bd1a880025fdff899c9ae9d6d44f040d2af59ea2..eb5d6e0e36e19d71b05fab97af4ad618d64367fa 100644 (file)
@@ -2155,6 +2155,10 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
 
     cblk->numbps = max ? (OPJ_UINT32)((opj_int_floorlog2(max) + 1) -
                                       T1_NMSEDEC_FRACBITS) : 0;
 
     cblk->numbps = max ? (OPJ_UINT32)((opj_int_floorlog2(max) + 1) -
                                       T1_NMSEDEC_FRACBITS) : 0;
+    if (cblk->numbps == 0) {
+        cblk->totalpasses = 0;
+        return;
+    }
 
     bpno = (OPJ_INT32)(cblk->numbps - 1);
     passtype = 2;
 
     bpno = (OPJ_INT32)(cblk->numbps - 1);
     passtype = 2;