fix(core): correct `debug_assert` in `get_button_border()`
What changed, and why it matters
This commit fixes an off-by-one error in a debug-only assertion inside a Trezor hardware wallet screen. The assertion checks whether a button index is valid, but it previously rejected the last valid button (the 'cancel' button). The fix changes '<' to '<=' so the assertion no longer falsely triggers. This is a minor correctness fix in debug builds and does not change release behavior or user-facing security.
No security action required. Treat as a normal code-quality/debugging fix. If auditing, confirm no other '< MAX_KEYS' checks elsewhere incorrectly exclude the cancel button index.
Security signals we found
Off-by-one in bounds check
Debug-only assertion correction
No release-runtime effect
Evidence from the diff
In core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs, two debug_assert! checks in get_button_border() and get_touch_expand() used idx < MAX_KEYS. Because there are MAX_KEYS value buttons plus an additional cancel button, the highest valid index is MAX_KEYS, making the original assertion incorrect by one. The patch changes both checks to idx <= MAX_KEYS. debug_assert! is compiled out in release builds, so this only affects panic behavior during development/testing and has no runtime effect on shipped firmware.
Changed components
core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rsTrezor Safe 5 / Eckhart layout UI keyboardInspect captured patch +2 / −2
diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
index 093dc82b..4196d08f 100644
--- a/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/word_count_screen.rs
@@ -166,7 +166,7 @@ impl ValueKeypad {
fn get_button_border(&self, idx: usize) -> Rect {
// Make sure the key is within bounds.
- debug_assert!(idx < MAX_KEYS);
+ debug_assert!(idx <= MAX_KEYS);
match idx {
0 => Rect::from_top_left_and_size(self.area.top_left(), Self::BUTTON_SIZE),
1 => Rect::from_center_and_size(
@@ -189,7 +189,7 @@ impl ValueKeypad {
}
fn get_touch_expand(&self, idx: usize) -> Insets {
- debug_assert!(idx < MAX_KEYS); // Ensure the index is within bounds.
+ debug_assert!(idx <= MAX_KEYS); // Ensure the index is within bounds.
let vertical_spacing = (self.area.height() - Self::BUTTON_SIZE.y * Self::ROWS as i16)
/ (Self::ROWS as i16 - 1);
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.