Skip to content

StripedBlockUtil.cpp: Potential integer overflow #71

Description

@stasos24

Since int64_t StripedBlockUtil::getInternalBlockLengt returns int64_t

int64_t StripedBlockUtil::getInternalBlockLength(int64_t dataSize, int32_t cellSize,
int32_t numDataBlocks, int32_t idxInBlockGroup) {
if (dataSize < 0 || cellSize <= 0 || numDataBlocks <= 0 || idxInBlockGroup < 0) {
THROW(InvalidParameter, "invalid parameter.");
}
// Size of each stripe (only counting data blocks)
int32_t stripeSize = cellSize * numDataBlocks;
// If block group ends at stripe boundary, each internal block has an equal
// share of the group
int32_t lastStripeDataLen = static_cast<int32_t>(dataSize % stripeSize);
if (lastStripeDataLen == 0) {
return dataSize / numDataBlocks;
}
int32_t numStripes = static_cast<int32_t>((dataSize - 1) / stripeSize + 1);
return (numStripes - 1) * cellSize
+ lastCellSize(lastStripeDataLen, cellSize, numDataBlocks, idxInBlockGroup);
}

and only dataSize has int64_t

there could be integer overflow at:

return (numStripes - 1) * cellSize
+ lastCellSize(lastStripeDataLen, cellSize, numDataBlocks, idxInBlockGroup);
}

Possible fix:
cast one of member of adddition to int64_t

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions