opj_t1_clbl_decode_processor(): avoid undefined behaviour if roishift >= 31. Fixes...
authorEven Rouault <even.rouault@spatialys.com>
Sat, 29 Jul 2017 14:29:11 +0000 (16:29 +0200)
committerEven Rouault <even.rouault@spatialys.com>
Sat, 29 Jul 2017 14:29:11 +0000 (16:29 +0200)
src/lib/openjp2/t1.c

index bd615d590a5347227f74b5dae69bd1b9fff424b7..3615a0e6690c6cfd3dd927459b3fa5bb7d4e10c2 100644 (file)
@@ -1685,14 +1685,22 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls)
     cblk_h = t1->h;
 
     if (tccp->roishift) {
-        OPJ_INT32 thresh = 1 << tccp->roishift;
-        for (j = 0; j < cblk_h; ++j) {
-            for (i = 0; i < cblk_w; ++i) {
-                OPJ_INT32 val = datap[(j * cblk_w) + i];
-                OPJ_INT32 mag = abs(val);
-                if (mag >= thresh) {
-                    mag >>= tccp->roishift;
-                    datap[(j * cblk_w) + i] = val < 0 ? -mag : mag;
+        if (tccp->roishift >= 31) {
+            for (j = 0; j < cblk_h; ++j) {
+                for (i = 0; i < cblk_w; ++i) {
+                    datap[(j * cblk_w) + i] = 0;
+                }
+            }
+        } else {
+            OPJ_INT32 thresh = 1 << tccp->roishift;
+            for (j = 0; j < cblk_h; ++j) {
+                for (i = 0; i < cblk_w; ++i) {
+                    OPJ_INT32 val = datap[(j * cblk_w) + i];
+                    OPJ_INT32 mag = abs(val);
+                    if (mag >= thresh) {
+                        mag >>= tccp->roishift;
+                        datap[(j * cblk_w) + i] = val < 0 ? -mag : mag;
+                    }
                 }
             }
         }