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

prevent invalid tile description enums #804

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
69 changes: 35 additions & 34 deletions OpenEXR/IlmImf/ImfHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,48 +913,49 @@ Header::sanityCheck (bool isTiled, bool isMultipartFile) const

if (isTiled)
{
if (!hasTileDescription())
{
throw IEX_NAMESPACE::ArgExc ("Tiled image has no tile "
"description attribute.");
}
if (!hasTileDescription())
{
throw IEX_NAMESPACE::ArgExc ("Tiled image has no tile "
"description attribute.");
}

const TileDescription &tileDesc = tileDescription();
const TileDescription &tileDesc = tileDescription();

if (tileDesc.xSize <= 0 || tileDesc.ySize <= 0 || tileDesc.xSize > INT_MAX || tileDesc.ySize > INT_MAX )
throw IEX_NAMESPACE::ArgExc ("Invalid tile size in image header.");
if (tileDesc.xSize <= 0 || tileDesc.ySize <= 0 || tileDesc.xSize > INT_MAX || tileDesc.ySize > INT_MAX )
throw IEX_NAMESPACE::ArgExc ("Invalid tile size in image header.");

if (maxTileWidth > 0 &&
maxTileWidth < int(tileDesc.xSize))
{
THROW (IEX_NAMESPACE::ArgExc, "The width of the tiles exceeds the maximum "
"width of " << maxTileWidth << "pixels.");
}
if (maxTileWidth > 0 &&
maxTileWidth < int(tileDesc.xSize))
{
THROW (IEX_NAMESPACE::ArgExc, "The width of the tiles exceeds the maximum "
"width of " << maxTileWidth << "pixels.");
}

if (maxTileHeight > 0 &&
maxTileHeight < int(tileDesc.ySize))
{
THROW (IEX_NAMESPACE::ArgExc, "The width of the tiles exceeds the maximum "
"width of " << maxTileHeight << "pixels.");
}
if (maxTileHeight > 0 &&
maxTileHeight < int(tileDesc.ySize))
{
THROW (IEX_NAMESPACE::ArgExc, "The width of the tiles exceeds the maximum "
"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)
throw IEX_NAMESPACE::ArgExc ("Invalid level mode in image header.");

if (tileDesc.mode != ONE_LEVEL &&
tileDesc.mode != MIPMAP_LEVELS &&
tileDesc.mode != RIPMAP_LEVELS)
throw IEX_NAMESPACE::ArgExc ("Invalid level mode in image header.");
if (tileDesc.roundingMode != ROUND_UP &&
tileDesc.roundingMode != ROUND_DOWN)
throw IEX_NAMESPACE::ArgExc ("Invalid level rounding mode in image header.");

if (lineOrder != INCREASING_Y &&
lineOrder != DECREASING_Y &&
lineOrder != RANDOM_Y)
throw IEX_NAMESPACE::ArgExc ("Invalid line order in image header.");

if (tileDesc.roundingMode != ROUND_UP &&
tileDesc.roundingMode != ROUND_DOWN)
throw IEX_NAMESPACE::ArgExc ("Invalid level rounding mode in image header.");
// computes size of chunk offset table. Throws an exception if this exceeds
// the maximum allowable size
getTiledChunkOffsetTableSize(*this);

if (lineOrder != INCREASING_Y &&
lineOrder != DECREASING_Y &&
lineOrder != RANDOM_Y)
throw IEX_NAMESPACE::ArgExc ("Invalid line order in image header.");
}
else
{
Expand Down
25 changes: 23 additions & 2 deletions OpenEXR/IlmImf/ImfTileDescriptionAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,29 @@ TileDescriptionAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream

unsigned char tmp;
Xdr::read <StreamIO> (is, tmp);
_value.mode = LevelMode (tmp & 0x0f);
_value.roundingMode = LevelRoundingMode ((tmp >> 4) & 0x0f);

//
// four bits are allocated for 'mode' for future use (16 possible values)
// but only values 0,1,2 are currently valid. '3' is a special valid enum value
// that indicates bad values have been used
//
// roundingMode can only be 0 or 1, and 2 is a special enum value for 'bad enum'
//
unsigned char levelMode = tmp & 0x0f;
if(levelMode > 3)
{
levelMode = 3;
}

_value.mode = LevelMode(levelMode);

unsigned char levelRoundingMode = (tmp >> 4) & 0x0f;
if(levelRoundingMode > 2)
{
levelRoundingMode = 2;
}

_value.roundingMode = LevelRoundingMode (levelRoundingMode);

}

Expand Down