From 57e2ec629b015194c4b6af0b66db56062c2a7c7e Mon Sep 17 00:00:00 2001 From: Steve Fan <19037626d@connect.polyu.hk> Date: Tue, 11 Jan 2022 17:16:45 +0800 Subject: [PATCH] comm_kernel: check if elements are within bounds for RPC list (#1824) --- artiq/coredevice/comm_kernel.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index bb8ed82fc..3889a39c1 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -476,11 +476,19 @@ class CommKernel: if tag_element == "b": self._write(bytes(value)) elif tag_element == "i": - self._write(struct.pack(self.endian + "%sl" % - len(value), *value)) + try: + self._write(struct.pack(self.endian + "%sl" % len(value), *value)) + except struct.error: + raise RPCReturnValueError( + "type mismatch: cannot serialize {value} as {type}".format( + value=repr(value), type="32-bit integer list")) elif tag_element == "I": - self._write(struct.pack(self.endian + "%sq" % - len(value), *value)) + try: + self._write(struct.pack(self.endian + "%sq" % len(value), *value)) + except struct.error: + raise RPCReturnValueError( + "type mismatch: cannot serialize {value} as {type}".format( + value=repr(value), type="64-bit integer list")) elif tag_element == "f": self._write(struct.pack(self.endian + "%sd" % len(value), *value))