diff --git a/src/vm.py b/src/vm.py index 9b86b06..b1b55dd 100644 --- a/src/vm.py +++ b/src/vm.py @@ -119,6 +119,11 @@ class VM: """ Make one step (only step into) """ + if self.pc.value * 4 > len(self.mem) - 4: + raise VMException( + VMExceptionType.END_OF_MEM, + self.pc.value + ) opcode = self.mem[self.pc.value * 4] opdesc = self._fetch_opcode_desc(opcode) args = self._parse_arguments(opdesc) @@ -148,6 +153,11 @@ class VM: self.continue_() def _fetch_opcode_desc(self, opcode: int): + if not opcode in OPCODES: + raise VMException( + VMExceptionType.INVALID_OPCODE, + self.pc.value + ) return OPCODES[opcode] def _parse_arguments(self, opdesc: OpcodeDescription) -> tuple[int, ...]: