From 5de0fb9382bbe3b4898d7d85c2199c52f46eff68 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 18 Dec 2013 20:44:30 -0800 Subject: [PATCH] Check for short packets in PGPPacket.from_bytes When the data is longer than expected, the packet may just be part of a stream. --- gpg-migrate.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gpg-migrate.py b/gpg-migrate.py index 905f8b6..00e672c 100755 --- a/gpg-migrate.py +++ b/gpg-migrate.py @@ -48,6 +48,9 @@ class PGPPacket (dict): offset += length_bytes self['length'] = _struct.unpack(length_format, length_data)[0] packet = data[offset:offset + self['length']] + if len(packet) < self['length']: + raise ValueError('packet too short ({} < {})'.format( + len(packet), self['length'])) offset += self['length'] return offset -- 2.26.2