8000
  • Data returned from Xlib/XGetEventData is not guaranteed to be aligned by Pewnack · Pull Request #610 · not-fl3/miniquad · GitHub
    [go: up one dir, main page]

    Skip to content

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

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

    not-fl3 merged 1 commit into
    not-fl3:masterfrom
    Pewnack:misaligned_pointer

    Conversation

    @Pewnack
    @Pewnack Pewnack commented Mar 22, 2026
    Copy link
    Copy Markdown
    Contributor

    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
    not-fl3 commented Mar 22, 2026
    Copy link
    Copy Markdown
    Owner

    Thanks for PR!

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

    Thanks for merging!

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

    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
    Pewnack commented Apr 9, 2026
    Copy link
    Copy Markdown
    Contributor Author

    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

    0