]> sigrok.org Git - libsigrokdecode.git/commitdiff
usb_packet: Handle truncated data packets.
authorVegard Storheil Eriksen <redacted>
Tue, 5 May 2020 18:27:26 +0000 (20:27 +0200)
committerSoeren Apel <redacted>
Tue, 1 Oct 2024 11:47:37 +0000 (13:47 +0200)
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.

decoders/usb_packet/pd.py

index e262074e0ba7d4bbd6a0fb57d022f22bdfc6159b..769db9a3a5ab92868cb4107f948ec8a16f51e1cc 100644 (file)
@@ -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])