Skip to content

Commit

Permalink
prevent overflow in RgbaFile cachePadding
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman authored and cary-ilm committed Jan 13, 2021
1 parent 9f0800d commit 189e8b5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib/OpenEXR/ImfRgbaFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ cachePadding (ptrdiff_t size)

static int LOG2_CACHE_LINE_SIZE = 8;

int i = LOG2_CACHE_LINE_SIZE + 2;
size_t i = LOG2_CACHE_LINE_SIZE + 2;

while ((size >> i) > 1)
++i;

if (size > (1 << (i + 1)) - 64)
return 64 + ((1 << (i + 1)) - size);
if (size > (1ll << (i + 1)) - 64ll)
return 64ll + ((1ll << (i + 1ll)) - size);

if (size < (1 << i) + 64)
return 64 + ((1 << i) - size);
if (size < (1ll << i) + 64ll)
return 64ll + ((1ll << i) - size);

return 0;
}
Expand Down

0 comments on commit 189e8b5

Please sign in to comment.