diff options
| author | Robert Collins <robertc@robertcollins.net> | 2015-08-02 16:18:58 +1200 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2015-08-04 15:38:46 +1200 |
| commit | cacd5f6bc6eed91f25434517eac0db75ef8fb1ac (patch) | |
| tree | eda0abedbafa7bae7c51cd1d0da2556a5045c063 /python/subunit/v2.py | |
| parent | a194e3e7cb4e5e5cd855da7eb906baaeea6cd2c2 (diff) | |
| download | subunit-git-cacd5f6bc6eed91f25434517eac0db75ef8fb1ac.tar.gz | |
Handle very short packets
Yay quickcheck.
Diffstat (limited to 'python/subunit/v2.py')
| -rw-r--r-- | python/subunit/v2.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/python/subunit/v2.py b/python/subunit/v2.py index 057f65c..f649895 100644 --- a/python/subunit/v2.py +++ b/python/subunit/v2.py @@ -386,7 +386,11 @@ class ByteStreamToStreamResult(object): def _parse(self, packet, result): # 2 bytes flags, at most 3 bytes length. packet.append(self.source.read(5)) - flags = struct.unpack(FMT_16, packet[-1][:2])[0] + if len(packet[-1]) != 5: + raise ParseError( + 'Short read - got %d bytes, wanted 5' % len(packet[-1])) + flag_bytes = packet[-1][:2] + flags = struct.unpack(FMT_16, flag_bytes)[0] length, consumed = self._parse_varint( packet[-1], 2, max_3_bytes=True) remainder = self.source.read(length - 6) |
