Origin: https://github.com/AcademySoftwareFoundation/openexr/commit/31472b638bb2bd7020a3465d6e6ddffd564ae0ea
Reviewed-by: Sylvain Beucler <beuc@debian.org>
Last-Update: 2021-07-30

From 31472b638bb2bd7020a3465d6e6ddffd564ae0ea Mon Sep 17 00:00:00 2001
From: peterhillman <peterh@wetafx.co.nz>
Date: Fri, 11 Sep 2020 11:03:48 +1200
Subject: [PATCH] Use Int64 in dataWindowForTile to prevent integer overflow
 (#831)

* Use Int64 in dataWindowForTile to prevent integer overflow

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>

* use signed 64 bit instead for dataWindow calculation

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>

Co-authored-by: Cary Phillips <cary@ilm.com>
---
 IlmImf/ImfTiledMisc.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/IlmImf/ImfTiledMisc.cpp b/IlmImf/ImfTiledMisc.cpp
index b8e195fd8..89ef97cb5 100644
--- a/IlmImf/ImfTiledMisc.cpp
+++ b/IlmImf/ImfTiledMisc.cpp
@@ -97,13 +97,14 @@ dataWindowForTile (const TileDescription &tileDesc,
     V2i tileMin = V2i (minX + dx * tileDesc.xSize,
 		       minY + dy * tileDesc.ySize);
 
-    V2i tileMax = tileMin + V2i (tileDesc.xSize - 1, tileDesc.ySize - 1);
+    int64_t tileMaxX = int64_t(tileMin[0]) + tileDesc.xSize - 1;
+    int64_t tileMaxY = int64_t(tileMin[1]) + tileDesc.ySize - 1;
 
     V2i levelMax = dataWindowForLevel
 		       (tileDesc, minX, maxX, minY, maxY, lx, ly).max;
 
-    tileMax = V2i (std::min (tileMax[0], levelMax[0]),
-		   std::min (tileMax[1], levelMax[1]));
+    V2i tileMax = V2i (std::min (tileMaxX, int64_t(levelMax[0])),
+		   std::min (tileMaxY, int64_t(levelMax[1])));
 
     return Box2i (tileMin, tileMax);
 }
