Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent invalid values in Channel's PixelType enum #785

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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