Avoid integer overflow in calculateNumTiles()
@@ -301,7 +301,11 @@ calculateNumTiles (int *numTiles,
{
for (int i = 0; i < numLevels; i++)
{
- numTiles[i] = (levelSize (min, max, i, rmode) + size - 1) / size;
+ int l = levelSize (min, max, i, rmode);
+ if (l >= std::numeric_limits<int>::max() - size + 1)
+ throw IEX_NAMESPACE::ArgExc ("Invalid size.");
+
+ numTiles[i] = (l + size - 1) / size;
}
}
