From: W. Trevor King Date: Thu, 19 Dec 2013 04:44:30 +0000 (-0800) Subject: Check for short packets in PGPPacket.from_bytes X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5de0fb9382bbe3b4898d7d85c2199c52f46eff68;p=gpg-migrate.git Check for short packets in PGPPacket.from_bytes When the data is longer than expected, the packet may just be part of a stream. --- 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