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

enforce limit on area of deep tiles to prevent excessive memory use #939

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 18 additions & 3 deletions src/lib/OpenEXR/ImfDeepTiledInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,24 @@ DeepTiledInputFile::initialize ()
_data->tileDesc = _data->header.tileDescription();
_data->lineOrder = _data->header.lineOrder();


_data->maxSampleCountTableSize = static_cast<size_t>(_data->tileDesc.ySize) *
static_cast<size_t>(_data->tileDesc.xSize) *
sizeof(int);


//
// impose limit of 2^32 bytes of storage for maxSampleCountTableSize
// (disallow files with very large tile areas that would otherwise cause excessive memory allocation)
//


if(_data->maxSampleCountTableSize > std::numeric_limits<unsigned int>::max())
{
THROW(IEX_NAMESPACE::ArgExc, "Deep tile size exceeds maximum permitted area");
}


//
// Save the dataWindow information
//
Expand Down Expand Up @@ -1034,9 +1052,6 @@ DeepTiledInputFile::initialize ()
for (size_t i = 0; i < _data->tileBuffers.size(); i++)
_data->tileBuffers[i] = new TileBuffer ();

_data->maxSampleCountTableSize = static_cast<size_t>(_data->tileDesc.ySize) *
static_cast<size_t>(_data->tileDesc.xSize) *
sizeof(int);

_data->sampleCountTableBuffer.resizeErase(_data->maxSampleCountTableSize);

Expand Down
19 changes: 16 additions & 3 deletions src/lib/OpenEXR/ImfDeepTiledOutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include <assert.h>
#include <map>
#include <algorithm>
#include <limits>

#include "ImfNamespace.h"

Expand Down Expand Up @@ -1197,6 +1198,21 @@ DeepTiledOutputFile::initialize (const Header &header)
_data->minY = dataWindow.min.y;
_data->maxY = dataWindow.max.y;

_data->maxSampleCountTableSize = _data->tileDesc.ySize *
_data->tileDesc.xSize *
sizeof(int);

//
// impose limit of 2^32 bytes of storage for maxSampleCountTableSize
// (disallow files with very large tile areas that would otherwise cause excessive memory allocation)
//

if(_data->maxSampleCountTableSize > std::numeric_limits<unsigned int>::max())
{
THROW(IEX_NAMESPACE::ArgExc, "Deep tile size exceeds maximum permitted area");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this message :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that was embarrassing! Exception message now revised

}


//
// Precompute level and tile information to speed up utility functions
//
Expand Down Expand Up @@ -1236,9 +1252,6 @@ DeepTiledOutputFile::initialize (const Header &header)
//ignore the existing value of chunkCount - correct it if it's wrong
_data->header.setChunkCount(getChunkOffsetTableSize(_data->header));

_data->maxSampleCountTableSize = _data->tileDesc.ySize *
_data->tileDesc.xSize *
sizeof(int);


for (size_t i = 0; i < _data->tileBuffers.size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OpenEXRUtil/ImfCheckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ runChecks(T& source,bool reduceMemory,bool reduceTime)
firstPartWide = true;
}

if( tileDescription.ySize * tileDescription.xSize <= gMaxTileSize)
if( tileSize <= gMaxTileSize)
{
largeTiles = false;
}
Expand Down