94b862
From 1f0dfe5a42911b6880a1445f13f6d615ddb55387 Mon Sep 17 00:00:00 2001
94b862
From: Michael Adams <mdadams@ece.uvic.ca>
94b862
Date: Fri, 4 Nov 2016 07:20:23 -0700
94b862
Subject: [PATCH] Fixed an integer overflow problem in the JPC codec that later
94b862
 resulted in the use of uninitialized data.
94b862
94b862
---
94b862
 src/libjasper/jpc/jpc_t2cod.c | 20 ++++++++++----------
94b862
 src/libjasper/jpc/jpc_t2cod.h | 20 ++++++++++----------
94b862
 2 files changed, 20 insertions(+), 20 deletions(-)
94b862
94b862
diff --git a/src/libjasper/jpc/jpc_t2cod.c b/src/libjasper/jpc/jpc_t2cod.c
94b862
index 08315dd..174442a 100644
94b862
--- a/src/libjasper/jpc/jpc_t2cod.c
94b862
+++ b/src/libjasper/jpc/jpc_t2cod.c
94b862
@@ -432,18 +432,18 @@ static int jpc_pi_nextcprl(register jpc_pi_t *pi)
94b862
 	  &pi->picomps[pi->compno]; pi->compno < JAS_CAST(int, pchg->compnoend) && pi->compno < pi->numcomps; ++pi->compno,
94b862
 	  ++pi->picomp) {
94b862
 		pirlvl = pi->picomp->pirlvls;
94b862
-		pi->xstep = pi->picomp->hsamp * (1 << (pirlvl->prcwidthexpn +
94b862
-		  pi->picomp->numrlvls - 1));
94b862
-		pi->ystep = pi->picomp->vsamp * (1 << (pirlvl->prcheightexpn +
94b862
-		  pi->picomp->numrlvls - 1));
94b862
+		pi->xstep = pi->picomp->hsamp * (JAS_CAST(uint_fast32_t, 1) <<
94b862
+		  (pirlvl->prcwidthexpn + pi->picomp->numrlvls - 1));
94b862
+		pi->ystep = pi->picomp->vsamp * (JAS_CAST(uint_fast32_t, 1) <<
94b862
+		  (pirlvl->prcheightexpn + pi->picomp->numrlvls - 1));
94b862
 		for (rlvlno = 1, pirlvl = &pi->picomp->pirlvls[1];
94b862
 		  rlvlno < pi->picomp->numrlvls; ++rlvlno, ++pirlvl) {
94b862
-			pi->xstep = JAS_MIN(pi->xstep, pi->picomp->hsamp * (1 <<
94b862
-			  (pirlvl->prcwidthexpn + pi->picomp->numrlvls -
94b862
-			  rlvlno - 1)));
94b862
-			pi->ystep = JAS_MIN(pi->ystep, pi->picomp->vsamp * (1 <<
94b862
-			  (pirlvl->prcheightexpn + pi->picomp->numrlvls -
94b862
-			  rlvlno - 1)));
94b862
+			pi->xstep = JAS_MIN(pi->xstep, pi->picomp->hsamp *
94b862
+			  (JAS_CAST(uint_fast32_t, 1) << (pirlvl->prcwidthexpn +
94b862
+			  pi->picomp->numrlvls - rlvlno - 1)));
94b862
+			pi->ystep = JAS_MIN(pi->ystep, pi->picomp->vsamp *
94b862
+			  (JAS_CAST(uint_fast32_t, 1) << (pirlvl->prcheightexpn +
94b862
+			  pi->picomp->numrlvls - rlvlno - 1)));
94b862
 		}
94b862
 		for (pi->y = pi->ystart; pi->y < pi->yend;
94b862
 		  pi->y += pi->ystep - (pi->y % pi->ystep)) {
94b862
diff --git a/src/libjasper/jpc/jpc_t2cod.h b/src/libjasper/jpc/jpc_t2cod.h
94b862
index 0a176c9..690e031 100644
94b862
--- a/src/libjasper/jpc/jpc_t2cod.h
94b862
+++ b/src/libjasper/jpc/jpc_t2cod.h
94b862
@@ -129,10 +129,10 @@ typedef struct {
94b862
 	jpc_pirlvl_t *pirlvls;
94b862
 
94b862
 	/* The horizontal sampling period. */
94b862
-	int hsamp;
94b862
+	uint_fast32_t hsamp;
94b862
 
94b862
 	/* The vertical sampling period. */
94b862
-	int vsamp;
94b862
+	uint_fast32_t vsamp;
94b862
 
94b862
 } jpc_picomp_t;
94b862
 
94b862
@@ -171,32 +171,32 @@ typedef struct {
94b862
 	int lyrno;
94b862
 
94b862
 	/* The x-coordinate of the current position. */
94b862
-	int x;
94b862
+	uint_fast32_t x;
94b862
 
94b862
 	/* The y-coordinate of the current position. */
94b862
-	int y;
94b862
+	uint_fast32_t y;
94b862
 
94b862
 	/* The horizontal step size. */
94b862
-	int xstep;
94b862
+	uint_fast32_t xstep;
94b862
 
94b862
 	/* The vertical step size. */
94b862
-	int ystep;
94b862
+	uint_fast32_t ystep;
94b862
 
94b862
 	/* The x-coordinate of the top-left corner of the tile on the reference
94b862
 	  grid. */
94b862
-	int xstart;
94b862
+	uint_fast32_t xstart;
94b862
 
94b862
 	/* The y-coordinate of the top-left corner of the tile on the reference
94b862
 	  grid. */
94b862
-	int ystart;
94b862
+	uint_fast32_t ystart;
94b862
 
94b862
 	/* The x-coordinate of the bottom-right corner of the tile on the
94b862
 	  reference grid (plus one). */
94b862
-	int xend;
94b862
+	uint_fast32_t xend;
94b862
 
94b862
 	/* The y-coordinate of the bottom-right corner of the tile on the
94b862
 	  reference grid (plus one). */
94b862
-	int yend;
94b862
+	uint_fast32_t yend;
94b862
 
94b862
 	/* The current progression change. */
94b862
 	jpc_pchg_t *pchg;