Skip to content

Commit

Permalink
sanity check preview attribute sizes
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 Aug 9, 2020
1 parent 849c677 commit 3cf874c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions OpenEXR/IlmImf/ImfPreviewImageAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ PreviewImageAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &i
Xdr::read <StreamIO> (is, width);
Xdr::read <StreamIO> (is, height);

if (width < 0 || height < 0)
{
throw IEX_NAMESPACE::InputExc("Invalid dimensions in Preview Image Attribute");
}

// total attribute size should be four bytes per pixel + 8 bytes for width and height dimensions
if (static_cast<Int64>(width) * static_cast<Int64>(height) * 4l + 8l != static_cast<Int64>(size) )
{
throw IEX_NAMESPACE::InputExc("Mismatch between Preview Image Attribute size and dimensions");
}

PreviewImage p (width, height);

int numPixels = p.width() * p.height();
Expand Down

0 comments on commit 3cf874c

Please sign in to comment.