Skip to content

Commit

Permalink
sanity check ScanlineInput bytesPerLine instead of lineOffset size (A…
Browse files Browse the repository at this point in the history
…cademySoftwareFoundation#863)

Signed-off-by: Peter Hillman <[email protected]>

Co-authored-by: Cary Phillips <[email protected]>
Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
peterhillman and cary-ilm committed May 12, 2021
1 parent e4c637c commit 1109037
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions OpenEXR/IlmImf/ImfScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,33 @@ void ScanLineInputFile::initialize(const Header& header)
_data->minY = dataWindow.min.y;
_data->maxY = dataWindow.max.y;

Compression comp = _data->header.compression();

_data->linesInBuffer =
numLinesInBuffer (comp);

int lineOffsetSize = (dataWindow.max.y - dataWindow.min.y +
_data->linesInBuffer) / _data->linesInBuffer;

//
// avoid allocating excessive memory due to large lineOffsets and bytesPerLine table sizes.
// If the chunktablesize claims to be large,
// check the file is big enough to contain the lineOffsets table before allocating memory
// in the bytesPerLineTable and the lineOffsets table.
// Attempt to read the last entry in the table. Either the seekg() or the read()
// call will throw an exception if the file is too small to contain the table
//
if (lineOffsetSize * _data->linesInBuffer > gLargeChunkTableSize)
{
Int64 pos = _streamData->is->tellg();
_streamData->is->seekg(pos + (lineOffsetSize-1)*sizeof(Int64));
Int64 temp;
OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::read <OPENEXR_IMF_INTERNAL_NAMESPACE::StreamIO> (*_streamData->is, temp);
_streamData->is->seekg(pos);

}


size_t maxBytesPerLine = bytesPerLineTable (_data->header,
_data->bytesPerLine);

Expand Down

0 comments on commit 1109037

Please sign in to comment.