Skip to content

Commit

Permalink
Fixed integer underflow in OgreDistortionPass
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Pecka <[email protected]>
  • Loading branch information
peci1 authored Apr 25, 2024
1 parent 0b7f695 commit 95dbf33
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 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,7 +235,8 @@ void OgreDistortionPass::CreateRenderPass()
// nonlegacy distortion modes.

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

0 comments on commit 95dbf33

Please sign in to comment.