Skip to content

Commit

Permalink
apply AcademySoftwareFoundation#825: Avoid overflow in calculateNumTi…
Browse files Browse the repository at this point in the history
…les when size=MAX_INT

Signed-off-by: Peter Hillman <[email protected]>
  • Loading branch information
cary-ilm authored and peterhillman committed Dec 6, 2020
1 parent 1632a37 commit 10b1c6a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions OpenEXR/IlmImf/ImfTiledMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,8 @@ calculateNumTiles (int *numTiles,
{
for (int i = 0; i < numLevels; i++)
{
int l = levelSize (min, max, i, rmode);
if (l > std::numeric_limits<int>::max() - size + 1)
throw IEX_NAMESPACE::ArgExc ("Invalid 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 10b1c6a

Please sign in to comment.