Skip to content

Commit

Permalink
Avoid overflow in calculateNumTiles when size=MAX_INT (AcademySoftwar…
Browse files Browse the repository at this point in the history
…eFoundation#825)

* Avoid overflow in calculateNumTiles when size=MAX_INT

Signed-off-by: Cary Phillips <[email protected]>

* Compute level size with 64 bits to avoid overflow

Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
cary-ilm committed May 12, 2021
1 parent ff65d03 commit 28ac26b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion OpenEXR/IlmImf/ImfTiledMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ calculateNumTiles (int *numTiles,
{
for (int i = 0; i < numLevels; i++)
{
numTiles[i] = (levelSize (min, max, i, rmode) + size - 1) / size;
// use 64 bits to avoid int overflow if size is large.
Int64 l = levelSize (min, max, i, rmode);
numTiles[i] = (l + size - 1) / size;
}
}

Expand Down

0 comments on commit 28ac26b

Please sign in to comment.