From 110280ed5ea4d1b6b113a17a41d0caf3a995e7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 8 Aug 2022 18:48:23 +0300 Subject: [PATCH] Avoid attempted reads past end of program image Previously if what could be a load, store, branch, or call instruction was located within last two bytes of the program image being disassembled, the disassembler would try to read out of bounds to get its address parameter. This change marks such cases as not being valid instructions. --- thingamajig_disasm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/thingamajig_disasm.py b/thingamajig_disasm.py index 2cf0a9b..e764d68 100644 --- a/thingamajig_disasm.py +++ b/thingamajig_disasm.py @@ -45,6 +45,7 @@ def segment(binary, origin): valid = True if not opcodes[opcode].rx and rx != 0: valid = False if not opcodes[opcode].ry and ry != 0: valid = False + if opcodes[opcode].addr and ip + 2 >= len(binary): valid = False if not valid: raw = binary[ip:ip + 1]