opj_t2_encode_packet(): avoid out of bound access of #1297, but likely not the proper fix 1298/head
authorEven Rouault <even.rouault@spatialys.com>
Wed, 2 Dec 2020 12:13:26 +0000 (13:13 +0100)
committerEven Rouault <even.rouault@spatialys.com>
Wed, 2 Dec 2020 12:13:26 +0000 (13:13 +0100)
src/lib/openjp2/t2.c

index e452edd19b2fa09eb2d3b57b417f373ac1e13e9f..55f07c0cab973e225e3c0e983f43f092f8878176 100644 (file)
@@ -815,6 +815,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno,
             continue;
         }
 
+        /* Avoid out of bounds access of https://github.com/uclouvain/openjpeg/issues/1297 */
+        /* but likely not a proper fix. */
+        if (precno >= res->pw * res->ph) {
+            opj_event_msg(p_manager, EVT_ERROR,
+                          "opj_t2_encode_packet(): accessing precno=%u >= %u\n",
+                          precno, res->pw * res->ph);
+            return OPJ_FALSE;
+        }
+
         prc = &band->precincts[precno];
         l_nb_blocks = prc->cw * prc->ch;
         cblk = prc->cblks.enc;