From: Vegard Storheil Eriksen Date: Tue, 5 May 2020 18:27:26 +0000 (+0200) Subject: usb_packet: Handle truncated data packets. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=80e993bab984143e645efe789fec35882063ace7;p=libsigrokdecode.git usb_packet: Handle truncated data packets. Attempting to decode a truncated data packet would raise an exception, leaving the decoder in a state where next packet will get appended to it and decoded as one packet. This patch adds an explicit check for length before trying to decode the data and CRC fields, allowing graceful handling of truncated packets. --- diff --git a/decoders/usb_packet/pd.py b/decoders/usb_packet/pd.py index e262074..769db9a 100644 --- a/decoders/usb_packet/pd.py +++ b/decoders/usb_packet/pd.py @@ -342,6 +342,10 @@ class Decoder(srd.Decoder): self.packet_summary += ' %02X' % db self.packet_summary += ' ]' + if len(packet) < 32: + self.putp([28, ['Invalid packet (shorter than 32 bits)']]) + return + # Convenience Python output (no annotation) for all bytes together. self.ss, self.es = self.bits[16][1], self.bits[-16][2] self.putpb(['DATABYTES', databytes])