Skip to content

Commit

Permalink
prevent invalid values in Channel's PixelType enum
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 Jul 18, 2020
1 parent 4d41e43 commit 180b17e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions OpenEXR/IlmImf/ImfChannelListAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ ChannelListAttribute::readValueFrom (IStream &is,
Xdr::read <StreamIO> (is, xSampling);
Xdr::read <StreamIO> (is, ySampling);

//
// prevent invalid values being written to PixelType enum
// by forcing all unknown types to NUM_PIXELTYPES which is also an invalid
// pixel type, but can be used as a PixelType enum value
// (Header::sanityCheck will throw an exception when files with invalid PixelTypes are read)
//
if (type != OPENEXR_IMF_INTERNAL_NAMESPACE::UINT &&
type != OPENEXR_IMF_INTERNAL_NAMESPACE::HALF &&
type != OPENEXR_IMF_INTERNAL_NAMESPACE::FLOAT)
{
type = OPENEXR_IMF_INTERNAL_NAMESPACE::NUM_PIXELTYPES;
}

_value.insert (name, Channel (PixelType (type),
xSampling,
ySampling,
Expand Down

0 comments on commit 180b17e

Please sign in to comment.