opj_t2_encode_packet(): avoid out of bound access of #1294, but likely not the proper fix 1296/head
authorEven Rouault <even.rouault@spatialys.com>
Tue, 1 Dec 2020 18:51:35 +0000 (19:51 +0100)
committerEven Rouault <even.rouault@spatialys.com>
Tue, 1 Dec 2020 18:51:35 +0000 (19:51 +0100)
src/lib/openjp2/t2.c

index 71472b499c5d487388613e5ca2174706d98a3008..e452edd19b2fa09eb2d3b57b417f373ac1e13e9f 100644 (file)
@@ -739,6 +739,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno,
                 continue;
             }
 
+            /* Avoid out of bounds access of https://github.com/uclouvain/openjpeg/issues/1294 */
+            /* 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];
             opj_tgt_reset(prc->incltree);
             opj_tgt_reset(prc->imsbtree);