From 1e66017bc6f14d57e0e0115ce8a5f9ad5031fe38 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Thu, 14 Jan 2021 11:19:14 -0500 Subject: [PATCH] keyboard_comm: check that vial.json doesn't reference matrix out of bounds --- src/main/python/keyboard_comm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/python/keyboard_comm.py b/src/main/python/keyboard_comm.py index bea5388..d245788 100644 --- a/src/main/python/keyboard_comm.py +++ b/src/main/python/keyboard_comm.py @@ -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]