8000 Windows: validate XBUTTON1/XBUTTON2 before indexing mouse state by lyn1dev · Pull Request #447 · emoon/rust_minifb · GitHub
[go: up one dir, main page]

Skip to content

Windows: validate XBUTTON1/XBUTTON2 before indexing mouse state - #447

Open
lyn1dev wants to merge 1 commit into
emoon:masterfrom
lyn1dev:fix/windows-xbutton-bounds
Open

lyn1dev wants to merge 1 commit into
emoon:masterfrom
lyn1dev:fix/windows-xbutton-bounds

Conversation

@lyn1dev
@lyn1dev lyn1dev commented Nov 26, 2026
Copy link
Copy Markdown

Fixes #416.

Summary

  • wnd_proc previously used GET_XBUTTON_WPARAM(wparam) (u16 HIWORD) directly in wnd.mouse.state[2 + button as usize] for WM_XBUTTONDOWN and WM_XBUTTONUP.
  • Out-of-range values (>= 6) caused an out-of-bounds panic inside extern "system" fn wnd_proc (aborting the process), and 0 or 3..=5 aliased other mouse button slots (such as MouseButton::Right at index 2).
  • Added update_xbutton_state in src/os/windows/mod.rs to match only winuser::XBUTTON1 (state[3]) and winuser::XBUTTON2 (state[4]) and ignore all other values.

Verification

  • Added tests/windows_xbutton.rs (wm_xbutton_handles_valid_buttons_and_ignores_zero and wm_xbutton_ignores_out_of_range_values) sending WM_XBUTTONDOWN/WM_XBUTTONUP via SendMessageW.
  • Confirmed the regression tests fail before the fix (reproducing the MouseButton::Right aliasing and index-8 OOB panic/abort) and pass after the fix.
  • cargo fmt -- --check, cargo test (6 unit tests, window_move, windows_xbutton, 34 doc-tests), and cargo clippy --tests pass.

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.

Windows: WM_XBUTTON messages can cause OOB index panic in wnd_proc

1 participant

0