sanity check preview attribute sizes
@@ -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();
