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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed integer underflow in OgreDistortionPass #994

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions ogre/src/OgreDistortionPass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ void OgreDistortionPass::CreateRenderPass()
distortedLocation,
newDistortedCoordinates,
currDistortedCoordinates;
unsigned int distortedIdx,
distortedCol,
unsigned int distortedIdx;
int distortedCol,
distortedRow;
double normalizedColLocation, normalizedRowLocation;

Expand All @@ -223,9 +223,9 @@ void OgreDistortionPass::CreateRenderPass()
focalLength);

// compute the index in the distortion map
distortedCol = static_cast<unsigned int>(round(distortedLocation.X() *
distortedCol = static_cast<int>(round(distortedLocation.X() *
this->dataPtr->distortionTexWidth));
distortedRow = static_cast<unsigned int>(round(distortedLocation.Y() *
distortedRow = static_cast<int>(round(distortedLocation.Y() *
this->dataPtr->distortionTexHeight));

// Note that the following makes sure that, for significant distortions,
Expand All @@ -235,8 +235,11 @@ void OgreDistortionPass::CreateRenderPass()
// nonlegacy distortion modes.

// Make sure the distorted pixel is within the texture dimensions
if (distortedCol < this->dataPtr->distortionTexWidth &&
distortedRow < this->dataPtr->distortionTexHeight)
if (distortedCol >= 0 && distortedRow >= 0 &&
static_cast<unsigned int>(distortedCol) <
this->dataPtr->distortionTexWidth &&
static_cast<unsigned int>(distortedRow) <
this->dataPtr->distortionTexHeight)
{
distortedIdx = distortedRow * this->dataPtr->distortionTexWidth +
distortedCol;
Expand Down