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 segmentation faults on 32-bit ARM devices running GNU/Linux #15

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

Conversation

7koi
Copy link
Contributor

@7koi 7koi commented Oct 19, 2023

I tried to run SRB2Kart on my ODROID-XU4, which is a 32-bit ARMv7h device, and I would consistently get segmentation faults when Z_MallocAlign() was called with an alignbits value greater than or equal to 32. I found that the 1<<alignbits call would overflow and evaluate to 0. This would then have 1 subtracted from it, causing an underflow and setting extrabytes equal to 0xFFFFFFFF. This excessively high value for extrabytes causes weird memory corruption errors that eventually lead to a segmentation fault.

I have corrected this issue by not subtracting 1 when an overflow is guaranteed to have occurred.

Weirdly enough, this problem does not occur on 64-bit Intel, even though an alignbits value of 64 would still cause an overflow. extrabytes is still set to 0 even when alignbits is 64. This probably has to do with differences in the CPU overflow flag when bit shifting too much to the left.

Another interesting thing is that https://github.com/STJr/SRB2 apparently had some memory management updates (STJr/SRB2@cee5eb4) that removed the left bit shift operation entirely, but these updates have not made their way into SRB2Kart yet.

…ably other 32-bit ARM devices like older Raspberry Pis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant