Skip to content

Commit

Permalink
fix unitialised pointer and double-delete bugs (#661)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <[email protected]>
  • Loading branch information
peterhillman authored Feb 23, 2020
1 parent a0e84f6 commit 817faac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions OpenEXR/IlmImf/ImfDeepTiledInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,15 @@ TileBufferTask::execute ()
_tileBuffer->uncompressedData = _tileBuffer->buffer;
}

//
// sanity check data size: the uncompressed data should be exactly
// 'sizeOfTile' (if it's less, the file is corrupt and there'll be a buffer overrun)
//
if(_tileBuffer->dataSize != sizeOfTile)
{
THROW (IEX_NAMESPACE::InputExc, "size mismatch when reading deep tile: expected " << sizeOfTile << "bytes of uncompressed data but got " << _tileBuffer->dataSize);
}

//
// Convert the tile of pixel data back from the machine-independent
// representation, and store the result in the frame buffer.
Expand Down
18 changes: 16 additions & 2 deletions OpenEXR/IlmImf/ImfTiledInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ TiledInputFile::Data::Data (int numThreads):
partNumber (-1),
multiPartBackwardSupport(false),
numThreads(numThreads),
multiPartFile(nullptr),
memoryMapped(false),
_streamData(NULL),
_deleteStream(false)
Expand Down Expand Up @@ -754,7 +755,7 @@ TiledInputFile::TiledInputFile (const char fileName[], int numThreads):
}
}
}
if ( _data->_streamData != 0)
if ( _data->_streamData != 0 && !isMultiPart(_data->version))
{
delete _data->_streamData->is;
_data->_streamData->is = is = 0;
Expand Down Expand Up @@ -879,7 +880,20 @@ TiledInputFile::TiledInputFile (InputPartData* part)
}
catch(...)
{
if (_data) delete _data;
if(_data)
{
if (!_data->memoryMapped)
{
for (size_t i = 0; i < _data->tileBuffers.size(); i++)
{
if(_data->tileBuffers[i])
{
delete [] _data->tileBuffers[i]->buffer;
}
}
}
delete _data;
}
throw;
}
}
Expand Down

0 comments on commit 817faac

Please sign in to comment.