Avoids undefined shift behaviour in m_dc_level_shift computation
authorEven Rouault <even.rouault@spatialys.com>
Wed, 26 Jul 2017 21:25:38 +0000 (23:25 +0200)
committerEven Rouault <even.rouault@spatialys.com>
Thu, 27 Jul 2017 16:10:03 +0000 (18:10 +0200)
Fixes warning found on clusterfuzz-testcase-minimized-5146316340461568
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2495

Credit to OSS Fuzz

src/lib/openjp2/j2k.c
tests/nonregression/CMakeLists.txt

index 6b86ddfe6eb9e9749f33c7a6777ce3b2c22379ab..8bd77f430c2fef6b36d54041baad39bedf751948 100644 (file)
@@ -2231,9 +2231,12 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
                           i, l_img_comp->dx, l_img_comp->dy);
             return OPJ_FALSE;
         }
-        if (l_img_comp->prec > 38) { /* TODO openjpeg won't handle more than ? */
+        /* Avoids later undefined shift in computation of */
+        /* p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps[i].m_dc_level_shift = 1
+                    << (l_image->comps[i].prec - 1); */
+        if (l_img_comp->prec > 32) {
             opj_event_msg(p_manager, EVT_ERROR,
-                          "Invalid values for comp = %d : prec=%u (should be between 1 and 38 according to the JPEG2000 norm)\n",
+                          "Invalid values for comp = %d : prec=%u (should be between 1 and 38 according to the JPEG2000 norm. OpenJpeg only supports up to 32)\n",
                           i, l_img_comp->prec);
             return OPJ_FALSE;
         }
@@ -6267,6 +6270,13 @@ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k,
         ++p_header_data;
         l_comp->sgnd = (l_comp_def >> 7) & 1;
         l_comp->prec = (l_comp_def & 0x7f) + 1;
+
+        if (l_comp->prec > 32) {
+            opj_event_msg(p_manager, EVT_ERROR,
+                          "Invalid values for comp = %d : prec=%u (should be between 1 and 38 according to the JPEG2000 norm. OpenJpeg only supports up to 32)\n",
+                          i, l_comp->prec);
+            return OPJ_FALSE;
+        }
         ++l_comp;
     }
 
index 187c1cb080f324bc30db31aee0ddae8ee9de9e1f..677f96cd282977115eb6fc4403f3e6e09463a17f 100644 (file)
@@ -82,6 +82,7 @@ set(BLACKLIST_JPEG2000
     issue476.jp2 #kdu_jp2info ok
     issue475.jp2 #kdu_jp2info ok
     issue413.jp2 #kdu_jp2info ok
+    issue823.jp2 #kdu_jp2info ok
    )
 
 file(GLOB_RECURSE OPJ_DATA_NR_LIST