Skip to content

fix(input): stop startup heap corruption from an undersized Raw Input device-name buffer - #1

Merged
E4crypt3d merged 2 commits into
E4crypt3d:mainfrom
Salmankbdev:fix/raw-input-device-name-overflow
Sep 6, 2026
Merged

E4crypt3d merged 2 commits into
E4crypt3d:mainfrom
Salmankbdev:fix/raw-input-device-name-overflow

Conversation

@Salmankbdev

Copy link
Copy Markdown
Contributor

What was wrong

The app crashes with 0xC0000374 (heap corruption) shortly after startup — sometimes instantly, sometimes a minute or two in. Earlier fixes treated symptoms (panic hook, catch_unwind, --disable-gpu-compositing); the real defect is in devices.rs::device_path.

GetRawInputDeviceInfoW's size query reports the device-name buffer size in WCHARs on current Windows, and the follow-up call writes the entire null-terminated name regardless of the size passed in. The code allocated size/2 + 4 WCHARs (~half the needed space), so every enumerated keyboard overflowed its heap block by roughly half the name length — silent memory corruption on every launch.

Verified with a canary probe against a real device list: the old allocation clobbered the guard region after the buffer on all devices; the corrected allocation (size + 1 WCHARs, safe under every bytes-vs-WCHARs interpretation) does not.

Fix

src-tauri/src/input/devices.rs — size the device-name buffer in characters (size + 1 WCHARs) instead of bytes.

Verification

  • Canary probe: no overflow after the fix, full device names still read back.
  • The dev build run under cdb with the Windows debug heap (which crashed the old binary in <2 s, 3/3 runs): 75 s clean run, no heap corruption, full UI up.
  • cargo test: 29 passed, 0 failed.

Release

Also bumps the app to 0.3.7 (Cargo.toml, tauri.conf.json, package.json, Cargo.lock) and adds the CHANGELOG entry. Merging triggers the automatic v0.3.7 release build per release.yml.

…ecause the raw-input device-name buffer was sized in bytes while Windows measures and writes that name in characters
@E4crypt3d
E4crypt3d merged commit 9ca357d into E4crypt3d:main Sep 6, 2026
E4crypt3d pushed a commit that referenced this pull request Sep 6, 2026
…flow

fix(input): stop startup heap corruption from an undersized Raw Input device-name buffer
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.

2 participants