summaryrefslogtreecommitdiffstats
path: root/Lib/plistlib.py
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2014-01-15 10:32:35 (GMT)
committerRonald Oussoren <ronaldoussoren@mac.com>2014-01-15 10:32:35 (GMT)
commit6db6653bbc0841600248e4d7b7542591067c4157 (patch)
tree1c3c992658e8f361b903bfcd3956956fcf7abf5e /Lib/plistlib.py
parent4a714d48ad727f6ad708ba2d3695f1dea4479fb6 (diff)
downloadcpython-6db6653bbc0841600248e4d7b7542591067c4157.zip
cpython-6db6653bbc0841600248e4d7b7542591067c4157.tar.gz
cpython-6db6653bbc0841600248e4d7b7542591067c4157.tar.bz2
Issue #14455: Fix some issues with plistlib
* Negative integer support in binary plists was broken * Better exception for invalid data * Fix the versionadded/versionchanged markup in the documentation * Add the interface cleanup to what's new for 3.4
Diffstat (limited to 'Lib/plistlib.py')
-rw-r--r--Lib/plistlib.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index 277ce62..8286456 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -478,7 +478,10 @@ class _PlistWriter(_DumbXMLWriter):
self.simple_element("false")
elif isinstance(value, int):
- self.simple_element("integer", "%d" % value)
+ if -1 << 63 <= value < 1 << 64:
+ self.simple_element("integer", "%d" % value)
+ else:
+ raise OverflowError(value)
elif isinstance(value, float):
self.simple_element("real", repr(value))
@@ -665,7 +668,8 @@ class _BinaryPlistParser:
return b''
elif tokenH == 0x10: # int
- return int.from_bytes(self._fp.read(1 << tokenL), 'big')
+ return int.from_bytes(self._fp.read(1 << tokenL),
+ 'big', signed=tokenL >= 3)
elif token == 0x22: # real
return struct.unpack('>f', self._fp.read(4))[0]
@@ -871,14 +875,22 @@ class _BinaryPlistWriter (object):
self._fp.write(b'\x09')
elif isinstance(value, int):
- if value < 1 << 8:
+ if value < 0:
+ try:
+ self._fp.write(struct.pack('>Bq', 0x13, value))
+ except struct.error:
+ raise OverflowError(value)
+ elif value < 1 << 8:
self._fp.write(struct.pack('>BB', 0x10, value))
elif value < 1 << 16:
self._fp.write(struct.pack('>BH', 0x11, value))
elif value < 1 << 32:
self._fp.write(struct.pack('>BL', 0x12, value))
else:
- self._fp.write(struct.pack('>BQ', 0x13, value))
+ try:
+ self._fp.write(struct.pack('>BQ', 0x13, value))
+ except struct.error:
+ raise OverflowError(value)
elif isinstance(value, float):
self._fp.write(struct.pack('>Bd', 0x23, value))
@@ -933,7 +945,7 @@ class _BinaryPlistWriter (object):
self._fp.write(struct.pack('>' + self._ref_format * s, *valRefs))
else:
- raise InvalidFileException()
+ raise TypeError(value)
def _is_fmt_binary(header):