toofishes/python-pgpdump — pull request #5 by muelli (2012-04-08 00:21:54+00:00)
Title: Made UID Packet parsing more robust against malformed UTF-8 encoding

I encountered a problem with the following packets:

Reading from byte 87414

Reading from byte 87484

Traceback (most recent call last):
File "/home/muelli/hg/openpgp-things/mypgpdump.py", line 38, in
sys.exit(main(sys.argv))
File "/home/muelli/hg/openpgp-things/mypgpdump.py", line 23, in main
for packet in data.packets():
File "/home/muelli/git/python-pgpdump/pgpdump/data.py", line 30, in packets
total_length, packet = construct_packet(self.data, offset)
File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 562, in construct_packet
packet = PacketType(tag, name, new, packet_data)
File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 410, in __init__
super(UserIDPacket, self).__init__(*args, **kwargs)
File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 21, in __init__
self.parse()
File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 413, in parse
self.user = self.data.decode('utf8')
File "/tmp/pgpdump/lib64/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf8 in position 7: invalid start byte

after the change, it decoded the packet to: