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

Fix undefined behavior in pixel get/set routines #4141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matoro
Copy link

@matoro matoro commented Jan 2, 2024

The unit tests only seem to exercise the UB in set_pixel_color, but I believe the same issue is present in get_pixel_color. There is no guarantee that the incoming pixel buffer is aligned, so casting it to a larger integer with alignment requirements can issue an unaligned load.

I've unified and simplified the LE/BE implementation divergence as much as possible. memcpy() should compile to roughly the same asm as a direct assignment. Tested on LE and BE.

Should fix #1313

The unit tests only seem to exercise the UB in set_pixel_color, but I
believe the same issue is present in get_pixel_color.  There is no
guarantee that the incoming pixel buffer is aligned, so casting it to a
larger integer with alignment requirements can issue an unaligned load.

I've unified and simplified the LE/BE implementation divergence as much
as possible.  memcpy() should compile to roughly the same asm as a
direct assignment.  Tested on LE and BE.

Should fix pygame#1313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined behaviour tests ubsan
2 participants