summaryrefslogtreecommitdiffstats
path: root/Lib/plistlib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-31 12:05:53 (GMT)
committerGitHub <noreply@github.com>2017-10-31 12:05:53 (GMT)
commitdb91e0fe2417f075693a194a492b1699829871e7 (patch)
tree10e3bacbd3cbf0c0c1b497ef57c8457eebfce424 /Lib/plistlib.py
parentb484d5606ca76f9bbd0f5de7a6ef753400213e94 (diff)
downloadcpython-db91e0fe2417f075693a194a492b1699829871e7.zip
cpython-db91e0fe2417f075693a194a492b1699829871e7.tar.gz
cpython-db91e0fe2417f075693a194a492b1699829871e7.tar.bz2
bpo-31897: Convert unexpected errors when read bogus binary plists into InvalidFileException. (#4171)
Diffstat (limited to 'Lib/plistlib.py')
-rw-r--r--Lib/plistlib.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index 8262fb0..2113a2d 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -557,7 +557,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):
@@ -575,6 +576,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))