mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
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:
parent
ece5659565
commit
6969d368c4
3 changed files with 70 additions and 5 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue