Skip to content

Commit

Permalink
Prevent reading or writing OpenEXR images with no channels (#911)
Browse files Browse the repository at this point in the history
* test for empty/missing channel lists

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>

* add channels to all images written/read by OpenEXRTest

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman committed Feb 1, 2021
1 parent bb0a501 commit dbcae60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/lib/OpenEXR/ImfHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,15 @@ Header::sanityCheck (bool isTiled, bool isMultipartFile) const
// x and y subsampling factors.
//




const ChannelList &channels = this->channels();

if (channels.begin()==channels.end())
{
THROW (IEX_NAMESPACE::ArgExc, "Missing or empty channel list in header");
}

if (isTiled || isDeep)
{
Expand Down
Binary file modified src/test/OpenEXRTest/invalid_shared_attrs_multipart.exr
Binary file not shown.
5 changes: 3 additions & 2 deletions src/test/OpenEXRTest/testBadTypeAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ const std::string & NOTYPEATTR="";
template<class IN,class OUT> void check(const char* filename,const string& inputtype,const string &outputtype,bool add_tiledesc)
{
Header f;

f.channels().insert("Dummy",Channel());

if(inputtype!=NOTYPEATTR)
{
f.setType(inputtype);
Expand All @@ -323,7 +324,7 @@ template<class IN,class OUT> void check(const char* filename,const string& input
}

{
IMF::MultiPartInputFile file(filename);
MultiPartInputFile file(filename);

if(outputtype!=NOTYPEATTR && file.header(0).type()!=outputtype)
{
Expand Down
1 change: 1 addition & 0 deletions src/test/OpenEXRTest/testDeepScanLineBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ void testCompressionTypeChecks()
{
Header h;
h.setType(DEEPTILE);
h.channels().insert("Dummy",Channel());
h.compression()=NO_COMPRESSION;
h.sanityCheck();
h.compression()=ZIPS_COMPRESSION;
Expand Down
6 changes: 6 additions & 0 deletions src/test/OpenEXRTest/testMultiPartSharedAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ void
testDisplayWindow (const vector<Header> & hs, const std::string & fn)
{
vector<Header> headers(hs);
headers[0].channels().insert("Dummy",Channel());
IMATH_NAMESPACE::Box2i newDisplayWindow = headers[0].displayWindow();
Header newHeader (newDisplayWindow.size().x+10, newDisplayWindow.size().y+10);
newHeader.setType (headers[0].type());
newHeader.channels() = headers[0].channels();
newHeader.setName (headers[0].name() + string("_newHeader"));
headers.push_back (newHeader);
testMultiPartOutputFileForExpectedFailure (headers,
Expand All @@ -196,6 +198,7 @@ testPixelAspectRatio (const vector<Header> & hs, const std::string & fn)
headers[0].pixelAspectRatio() + 1.f);
newHeader.setType (headers[0].type());
newHeader.setName (headers[0].name() + string("_newHeader"));
newHeader.channels().insert("Dummy",Channel());
headers.push_back (newHeader);
testMultiPartOutputFileForExpectedFailure (headers,
fn,
Expand All @@ -211,6 +214,7 @@ testTimeCode (const vector<Header> & hs, const std::string & fn)

Header newHeader (headers[0]);
newHeader.setName (headers[0].name() + string("_newHeader"));
newHeader.channels().insert("Dummy",Channel());


//
Expand Down Expand Up @@ -251,6 +255,7 @@ testChromaticities (const vector<Header> & hs, const std::string & fn)

Header newHeader (headers[0]);
newHeader.setName (headers[0].name() + string("_newHeader"));
newHeader.channels().insert("Dummy",Channel());

Chromaticities c;
ChromaticitiesAttribute ca(c);
Expand Down Expand Up @@ -359,6 +364,7 @@ testHeaders (const std::string & fn)
// expect this to fail - header has no image attribute type
//
Header h;
h.channels().insert("Dummy",Channel());
headers.push_back (h);
testMultiPartOutputFileForExpectedFailure (headers,
fn,
Expand Down

0 comments on commit dbcae60

Please sign in to comment.