Skip to content

Fix out-of-bounds row in Keychron RGB LED index query - #553

Open
edusperoni wants to merge 1 commit into
Keychron:2025q3from
edusperoni:fix-rgb-led-idx-row-bound
Open

edusperoni wants to merge 1 commit into
Keychron:2025q3from
edusperoni:fix-rgb-led-idx-row-bound

Conversation

@edusperoni

Copy link
Copy Markdown

Description

rgb_get_led_idx (Keychron RGB protocol, RGB_GET_LED_IDX) rejects rows with row > MATRIX_ROWS, so the query for row == MATRIX_ROWS is accepted. It then reads one row past the end of g_led_config.matrix_co, i.e. the start of g_led_config.point, and returns those coordinate bytes as LED indices with a success status.

Responses from a C3 Pro 8K (6×17 matrix) before this change, as [status, col0, col1, …]:

row 5: status 0  [78, 79, 80, 255, 255, 255, 81, 255, 255, 255, 82, 83, 84, 85, 86, 87, 88]
row 6: status 0  [0, 0, 26, 0, 39, 0, 52, 0, 65, 0, 84, 0, 97, 0, 110, 0, 123]   <- g_led_config.point bytes
row 7: status 1  (rejected)

Host software that scans rows until the firmware rejects one, such as OpenRGB's Keychron controller, then places an unrelated LED in a row that doesn't exist. On the C3 Pro 8K, side light 97 shows up at (6,12). Boards whose point bytes only match LEDs that are already placed aren't visibly affected, but every board built with keychron_rgb.c returns the out-of-bounds data.

The fix uses >=, matching the other matrix bounds checks in keyboards/keychron/common (for example analog_matrix.c).

Built keychron/c3_pro_8k/iso:keychron, keychron/q1_max/ansi_encoder:keychron and keychron/k8_max/ansi/rgb:keychron.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • None filed.

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

rgb_get_led_idx accepted row == MATRIX_ROWS and read one row past the
end of g_led_config.matrix_co, returning bytes of g_led_config.point as
LED indices. Hosts that scan rows until the firmware rejects one, such as
OpenRGB, then place an unrelated LED in a row that does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant