Skip to content

Data returned from Xlib/XGetEventData is not guaranteed to be aligned#610

Merged
not-fl3 merged 1 commit intonot-fl3:masterfrom
Pewnack:misaligned_pointer
Mar 22, 2026
Merged

Data returned from Xlib/XGetEventData is not guaranteed to be aligned#610
not-fl3 merged 1 commit intonot-fl3:masterfrom
Pewnack:misaligned_pointer

Conversation

@Pewnack
Copy link
Copy Markdown
Contributor

@Pewnack Pewnack commented Mar 22, 2026

Fixes #394
Data returned from Xlib is not guaranteed to be aligned. This could cause a "misaligned pointer deference" panic when getting the mouse deltas. The mouse deltas are two doubles, but the buffer in which they are stored might not be 8 byte aligned. This apparently could happen quite easily on a Linux 32 bit system.

Tested it on a 32bit Raspberry PI. Also tested this on a Ubuntu 64bit, just to see It didn't break anything there.

@not-fl3
Copy link
Copy Markdown
Owner

not-fl3 commented Mar 22, 2026

Thanks for PR!

@not-fl3 not-fl3 merged commit 7be7598 into not-fl3:master Mar 22, 2026
11 checks passed
@Pewnack
Copy link
Copy Markdown
Contributor Author

Pewnack commented Mar 22, 2026

Thanks for merging!

@Pewnack Pewnack deleted the misaligned_pointer branch March 22, 2026 20:50
@bolphen
Copy link
Copy Markdown
Contributor

bolphen commented Apr 8, 2026

When reading dy the pointer is shifted by just one byte instead of 8 so the returned value is no longer correct after this PR...

Probably could just do the following?

        let dx = std::ptr::read_unaligned((*raw_event).raw_values);
        let dy = std::ptr::read_unaligned((*raw_event).raw_values.add(1));

@Pewnack
Copy link
Copy Markdown
Contributor Author

Pewnack commented Apr 9, 2026

Thanks for pointing this out! Thought I properly tested this on X11, but my system is still running Wayland apparently. I'll make a fix.

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.

Crash with "misaligned pointer dereference" in xi_input.rs in 32-bit Linux

3 participants