From 713429b8faa94ddb169b6d8147c421d0bb8756af Mon Sep 17 00:00:00 2001 From: TryLab <494467347@qq.com> Date: Tue, 16 Aug 2016 17:22:57 +0800 Subject: [PATCH] Fix an integer overflow issue Prevent an integer overflow issue in function opj_pi_create_decode of pi.c. --- src/lib/openjp2/pi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c index cffad668..bf9c2e9c 100644 --- a/src/lib/openjp2/pi.c +++ b/src/lib/openjp2/pi.c @@ -36,6 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include "opj_includes.h" /** @defgroup PI PI - Implementation of a packet iterator */ @@ -1237,7 +1238,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, l_current_pi = l_pi; /* memory allocation for include */ - l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); + /* prevent an integer overflow issue */ + l_current_pi->include = 00; + if (l_step_l && l_tcp->numlayers < UINT_MAX / l_step_l - 1) + { + l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); + } + if (!l_current_pi->include) {