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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image fields should be private for soundness #746

Open
cyrgani opened this issue Jun 23, 2024 · 0 comments · May be fixed by #748 or #878
Open

Image fields should be private for soundness #746

cyrgani opened this issue Jun 23, 2024 · 0 comments · May be fixed by #748 or #878
Labels
enhancement New feature or request

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Jun 23, 2024

The following safe code causes undefined behaviour by reading out of bounds:

fn main() {
    let mut image = macroquad::texture::Image::empty();
    image.width += 1;
    image.height += 1;
    dbg!(image.get_image_data());
}

To fix this, all the fields of Image should become private, which would be a breaking change.
The Image::width and Image::height methods for immutable reading already exist as a replacement, along with Image::get_image_data.

Unsafe methods for changing the width and height could be added too if there is a legitimate use case.

@not-fl3 not-fl3 added the enhancement New feature or request label Jun 23, 2024
@cyrgani cyrgani linked a pull request Jun 24, 2024 that will close this issue
@cyrgani cyrgani linked a pull request Jan 10, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants