Skip to content

Commit

Permalink
Fix heap overflow when reading
Browse files Browse the repository at this point in the history
PF_RGB is 3 bytes. But later on Ogre2SelectionBuffer::OnSelectionClick
will try to read 4 bytes from it.

Fixed by ensuring it's always at least 4 bytes and zero-initializing
those 4 bytes.

Signed-off-by: Matias N. Goldberg <[email protected]>
  • Loading branch information
darksylinc committed Jun 14, 2021
1 parent f9f1820 commit 598aca1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ogre2/src/Ogre2SelectionBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ void Ogre2SelectionBuffer::CreateRTTBuffer()
const_cast<Ogre::CompositorPassSceneDef *>(scenePass)->mVisibilityMask =
IGN_VISIBILITY_SELECTABLE;

// buffer to store render texture data
size_t bufferSize = Ogre::PixelUtil::getMemorySize(width, height, 1, format);
// buffer to store render texture data. Ensure it's at least 4 bytes
size_t bufferSize = std::min<size_t>(
Ogre::PixelUtil::getMemorySize(width, height, 1, format),
4u);
this->dataPtr->buffer = new uint8_t[bufferSize];
memset(this->dataPtr->buffer, 0, 4u);
this->dataPtr->pixelBox = new Ogre::PixelBox(width,
height, 1, format, this->dataPtr->buffer);
}
Expand Down

0 comments on commit 598aca1

Please sign in to comment.