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

Fix for #263: prevent overflow in multipart chunk offset reconstruction #433

Merged
merged 3 commits into from
Jul 12, 2019
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
24 changes: 11 additions & 13 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 @@ -571,10 +571,9 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA



if(partNumber<0 || partNumber>int(parts.size()))
if(partNumber<0 || partNumber> static_cast<int>(parts.size()))
{
// bail here - bad part number
throw int();
throw IEX_NAMESPACE::IoExc("part number out of range");
}

Header& header = parts[partNumber]->header;
Expand All @@ -601,14 +600,13 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA
{
// this shouldn't actually happen - we should have allocated a valid
// tileOffsets for any part which isTiled
throw int();
throw IEX_NAMESPACE::IoExc("part not tiled");

}

if(!tileOffsets[partNumber]->isValidTile(tilex,tiley,levelx,levely))
{
//std::cout << "invalid tile : aborting\n";
throw int();
throw IEX_NAMESPACE::IoExc("invalid tile coordinates");
}

(*tileOffsets[partNumber])(tilex,tiley,levelx,levely)=chunk_start;
Expand Down Expand Up @@ -639,18 +637,20 @@ 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)
{
throw IEX_NAMESPACE::IoExc("y out of range");
}
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
throw int();
throw IEX_NAMESPACE::IoExc("chunk index out of range");
}

parts[partNumber]->chunkOffsets[y_coordinate]=chunk_start;
//std::cout << "chunk_start for " << y_coordinate << ':' << chunk_start << std::endl;

if(header.type()==DEEPSCANLINE)
{
Expand Down Expand Up @@ -678,8 +678,6 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA

chunk_start+=size_of_chunk;

//std::cout << " next chunk +"<<size_of_chunk << " = " << chunk_start << std::endl;

is.seekg(chunk_start);

}
Expand Down