bpo-31897: Convert unexpected errors when read bogus binary plists into InvalidFileException. (GH-4171) (#4192)

(cherry picked from commit db91e0fe24)
This commit is contained in:
Miss Islington (bot) 2017-10-31 06:58:55 -07:00 committed by Serhiy Storchaka
parent ece5659565
commit 6969d368c4
3 changed files with 70 additions and 5 deletions

View file

@ -622,7 +622,8 @@ class _BinaryPlistParser:
self._object_offsets = self._read_ints(num_objects, offset_size)
return self._read_object(self._object_offsets[top_object])
except (OSError, IndexError, struct.error):
except (OSError, IndexError, struct.error, OverflowError,
UnicodeDecodeError):
raise InvalidFileException()
def _get_size(self, tokenL):
@ -640,6 +641,8 @@ class _BinaryPlistParser:
if size in _BINARY_FORMAT:
return struct.unpack('>' + _BINARY_FORMAT[size] * n, data)
else:
if not size or len(data) != size * n:
raise InvalidFileException()
return tuple(int.from_bytes(data[i: i + size], 'big')
for i in range(0, size * n, size))