Repository navigation
fix(gamepad-demo): avoid OOB when device name fills the buffer - #273
Conversation
record() capped names at NAME_CAP, so name_len could equal NAME_CAP (64) and nameFor's sentinel slice e.name[0..name_len :0] read index 64 of a [64]u8 -> out-of-bounds panic. Cap record at NAME_CAP-1 (reserve the NUL) and clamp in nameFor; add a buffer-filling regression test. (Re-do of a #272-review fix that was lost to a detached-worktree push no-op.)
PR SummaryLow Risk Overview
Adds a regression test that records a name longer than Reviewed by Cursor Bugbot for commit 584c2cc. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Code Review
This pull request fixes an out-of-bounds panic bug in examples/gamepad-android/scripts/connected_pads.zig by capping the gamepad name length at NAME_CAP - 1 in record and defensively clamping and terminating the name in nameFor. A test case has also been added to verify this behavior. The reviewer notes that the same bug exists in examples/gamepad/scripts/connected_pads.zig and recommends applying the same fix there to prevent crashes on non-Android platforms.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // Cap at NAME_CAP-1 so a terminator always fits within the fixed buffer | ||
| // (nameFor returns a sentinel-terminated slice; a name filling all | ||
| // NAME_CAP bytes would leave no room for the NUL → OOB). | ||
| const n = @min(name.len, NAME_CAP - 1); |
Follow-up to #272.
record()capped names atNAME_CAP, soname_lencould equalNAME_CAP(64) andnameFor's sentinel slicee.name[0..name_len :0]read index 64 of a[64]u8→ out-of-bounds panic. CapsrecordatNAME_CAP-1(reserve the NUL) and clamps innameFor; adds a buffer-filling regression test. Both host tests pass.(Caught in #272's review but lost to the same detached-worktree push no-op; re-applying properly.)