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

Address #270: limit Tiled images to INT_MAX total number of tiles #423

Merged
merged 2 commits into from
Jul 10, 2019
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
6 changes: 5 additions & 1 deletion OpenEXR/IlmImf/ImfHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#include <sstream>
#include <stdlib.h>
#include <time.h>

#include "ImfTiledMisc.h"
#include "ImfNamespace.h"

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
Expand Down Expand Up @@ -915,6 +915,10 @@ Header::sanityCheck (bool isTiled, bool isMultipartFile) const
"width of " << maxTileHeight << "pixels.");
}

// computes size of chunk offset table. Throws an exception if this exceeds
// the maximum allowable size
getTiledChunkOffsetTableSize(*this);

if (tileDesc.mode != ONE_LEVEL &&
tileDesc.mode != MIPMAP_LEVELS &&
tileDesc.mode != RIPMAP_LEVELS)
Expand Down
26 changes: 20 additions & 6 deletions OpenEXR/IlmImf/ImfTiledMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,42 @@ getTiledChunkOffsetTableSize(const Header& header)
//
// Calculate lineOffsetSize.
//
int lineOffsetSize = 0;
Int64 lineOffsetSize = 0;
const TileDescription &desc = header.tileDescription();
switch (desc.mode)
{
case ONE_LEVEL:
case MIPMAP_LEVELS:
for (int i = 0; i < numXLevels; i++)
lineOffsetSize += numXTiles[i] * numYTiles[i];
break;
{
lineOffsetSize += static_cast<Int64>(numXTiles[i]) * static_cast<Int64>(numYTiles[i]);
if ( lineOffsetSize > std::numeric_limits<int>::max() )
{
throw IEX_NAMESPACE::LogicExc("Maximum number of tiles exceeded");
}
}
break;
case RIPMAP_LEVELS:
for (int i = 0; i < numXLevels; i++)
{
for (int j = 0; j < numYLevels; j++)
lineOffsetSize += numXTiles[i] * numYTiles[j];
break;
{
lineOffsetSize += static_cast<Int64>(numXTiles[i]) * static_cast<Int64>(numYTiles[j]);
if ( lineOffsetSize > std::numeric_limits<int>::max() )
{
throw IEX_NAMESPACE::LogicExc("Maximum number of tiles exceeded");
}
}
}
break;
case NUM_LEVELMODES :
throw IEX_NAMESPACE::LogicExc("Bad level mode getting chunk offset table size");
}

delete[] numXTiles;
delete[] numYTiles;

return lineOffsetSize;
return static_cast<int>(lineOffsetSize);
}


Expand Down