Skip to content

Commit

Permalink
Use Int64 in dataWindowForTile to prevent integer overflow (#831)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
peterhillman and cary-ilm authored Sep 10, 2020
1 parent d80f11f commit 31472b6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions OpenEXR/IlmImf/ImfTiledMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 31472b6

Please sign in to comment.