keyboard_comm: check that vial.json doesn't reference matrix out of bounds

main
Ilya Zhuravlev 2021-01-14 11:19:14 -05:00
parent 8239e06de3
commit 1e66017bc6
1 changed files with 3 additions and 0 deletions

View File

@ -163,6 +163,9 @@ class Keyboard:
for layer in range(self.layers):
for row, col in self.rowcol.keys():
if row >= self.rows or col >= self.cols:
raise RuntimeError("malformed vial.json, key references {},{} but matrix declares rows={} cols={}"
.format(row, col, self.rows, self.cols))
# determine where this (layer, row, col) will be located in keymap array
offset = layer * self.rows * self.cols * 2 + row * self.cols * 2 + col * 2
keycode = struct.unpack(">H", keymap[offset:offset+2])[0]