Skip to content

Fix read from unknown address in Image::get_pixel#12

Merged
madmiraal merged 1 commit into
RebelToolbox:mainfrom
madmiraal:fix-read-from-unknown-address
Jul 4, 2023
Merged

Fix read from unknown address in Image::get_pixel#12
madmiraal merged 1 commit into
RebelToolbox:mainfrom
madmiraal:fix-read-from-unknown-address

Conversation

@madmiraal
Copy link
Copy Markdown
Contributor

Currently calls to Image::get_pixel() and Image::set_pixel() only perform validity checks when debug is enabled. The checks performed are:

  • Has the Image been locked?
  • Has the Image been initialised (performed when locking the image)?
  • Are the x and y parameters within the image dimensions?

This is presumably done for performance reasons, but it can result in reads and writes from and to invalid memory addresses when running a released game.

This PR separates internal and external calls to Image::get_pixel() and Image::set_pixel(). Validity checks are always performed when external calls are made to Image::get_pixel() and Image::set_pixel(). Validity checks are not performed when internal calls are made to Image::get_pixel() and Image::set_pixel(). Validity checks are not desired on internal calls, because they are made during nested loop calls, and validity checks are not required on internal calls, because validity checks will have already been performed outside of the nested loops.

Perform validity checks for external calls to get_pixel and set_pixel.
Don't perform validity checks for interal calls to get_pixel and set_pixel.
@madmiraal madmiraal added the bug label Jul 4, 2023
@madmiraal madmiraal self-assigned this Jul 4, 2023
@madmiraal madmiraal merged commit 25f3629 into RebelToolbox:main Jul 4, 2023
@madmiraal madmiraal deleted the fix-read-from-unknown-address branch July 4, 2023 20:01
@madmiraal madmiraal added PR Type: Bug Fix Your current game should now work as expected. and removed bug labels May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR Type: Bug Fix Your current game should now work as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant