Skip to content

Commit

Permalink
abort when file claims to have excessive scanline data requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman committed Jan 22, 2020
1 parent 904bc10 commit 4dbf8c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions OpenEXR/IlmImf/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ bytesPerLineTable (const Header &header,
c != channels.end();
++c)
{
int nBytes = pixelTypeSize (c.channel().type) *
(dataWindow.max.x - dataWindow.min.x + 1) /
c.channel().xSampling;
size_t nBytes = size_t(pixelTypeSize (c.channel().type)) *
size_t(dataWindow.max.x - dataWindow.min.x + 1) /
size_t(c.channel().xSampling);

for (int y = dataWindow.min.y, i = 0; y <= dataWindow.max.y; ++y, ++i)
if (modp (y, c.channel().ySampling) == 0)
Expand Down
8 changes: 8 additions & 0 deletions OpenEXR/IlmImf/ImfScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,12 @@ void ScanLineInputFile::initialize(const Header& header)

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

if(maxBytesPerLine > INT_MAX)
{
throw IEX_NAMESPACE::InputExc("maximum bytes per scanline exceeds maximum permissible size");
}


for (size_t i = 0; i < _data->lineBuffers.size(); i++)
{
Expand Down Expand Up @@ -1156,6 +1162,8 @@ void ScanLineInputFile::initialize(const Header& header)
}
catch (...)
{
if (_data->partNumber == -1)
delete _streamData;
delete _data;
_data=NULL;
throw;
Expand Down

0 comments on commit 4dbf8c8

Please sign in to comment.