Skip to content

Commit

Permalink
throw better exceptions in multipart chunk reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhillman committed Jul 12, 2019
1 parent 6e4b6ac commit 001a852
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions OpenEXR/IlmImf/ImfMultiPartInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA

if(partNumber<0 || partNumber>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 @@ -642,20 +640,17 @@ MultiPartInputFile::Data::chunkOffsetReconstruction(OPENEXR_IMF_INTERNAL_NAMESPA

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();
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()))
{
//bail to exception catcher: broken scanline: out of range of chunk table size
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 @@ -683,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

0 comments on commit 001a852

Please sign in to comment.