1 diff --git a/third_party/libopenjpeg20/pi.c b/third_party/libopenjpeg20/pi.c 2 index 1697bcb..06f1e41 100644 3 --- a/third_party/libopenjpeg20/pi.c 4 +++ b/third_party/libopenjpeg20/pi.c 5 @@ -36,6 +36,7 @@ 6 * POSSIBILITY OF SUCH DAMAGE. 7 */ 8 9 +#include <limits.h> 10 #include "opj_includes.h" 11 12 /** @defgroup PI PI - Implementation of a packet iterator */ 13 @@ -1236,7 +1237,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, 14 l_current_pi = l_pi; 15 16 /* memory allocation for include */ 17 - l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); 18 + l_current_pi->include = 00; 19 + if 20 + (l_step_l && l_tcp->numlayers < UINT_MAX / l_step_l - 1) 21 + { 22 + l_current_pi->include = (OPJ_INT16*)opj_calloc((l_tcp->numlayers + 1) * l_step_l, sizeof(OPJ_INT16)); 23 + } 24 + 25 if 26 (!l_current_pi->include) 27 { 28