Skip to content

Commit

Permalink
Fix for #263: prevent overflow in multipart chunk offset table recons…
Browse files Browse the repository at this point in the history
…truction
  • Loading branch information
peterhillman committed Jul 12, 2019
1 parent 395aa4c commit 6e4b6ac
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions OpenEXR/IlmImf/ImfMultiPartInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA

vector<TileOffsets*> tileOffsets(parts.size());

// for scanline-based parts, number of scanlines in each part
// for scanline-based parts, number of scanlines in each chunk
vector<int> rowsizes(parts.size());

for(size_t i = 0 ; i < parts.size() ; i++)
Expand Down Expand Up @@ -639,13 +639,18 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA
int y_coordinate;
OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::read <OPENEXR_IMF_INTERNAL_NAMESPACE::StreamIO> (is, y_coordinate);


if(y_coordinate < header.dataWindow().min.y || y_coordinate > header.dataWindow().max.y)
{
// bail to exception catcher: y out of range. Test now to prevent overflow in following arithmetic
throw int();
}
y_coordinate -= header.dataWindow().min.y;
y_coordinate /= rowsizes[partNumber];

if(y_coordinate < 0 || y_coordinate >= int(parts[partNumber]->chunkOffsets.size()))
{
//std::cout << "aborting reconstruction: bad data " << y_coordinate << endl;
//bail to exception catcher: broken scanline
//bail to exception catcher: broken scanline: out of range of chunk table size
throw int();
}

Expand Down

0 comments on commit 6e4b6ac

Please sign in to comment.