From 7338ebc4ba00366fa2c4f592630c2acd98c178d8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 4 Oct 2016 20:04:30 +0300 Subject: Issue #28321: Fixed writing non-BMP characters with binary format in plistlib. --- Lib/plistlib.py | 2 +- Lib/test/test_plistlib.py | 7 +++++++ Misc/NEWS | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/plistlib.py b/Lib/plistlib.py index b66639c..2502b39 100644 --- a/Lib/plistlib.py +++ b/Lib/plistlib.py @@ -918,7 +918,7 @@ class _BinaryPlistWriter (object): self._write_size(0x50, len(value)) except UnicodeEncodeError: t = value.encode('utf-16be') - self._write_size(0x60, len(value)) + self._write_size(0x60, len(t) // 2) self._fp.write(t) diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index 16114f9..692cac4 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -361,6 +361,13 @@ class TestPlistlib(unittest.TestCase): plistlib.dumps, testString) + def test_non_bmp_characters(self): + pl = {'python': '\U0001f40d'} + for fmt in ALL_FORMATS: + with self.subTest(fmt=fmt): + data = plistlib.dumps(pl, fmt=fmt) + self.assertEqual(plistlib.loads(data), pl) + def test_nondictroot(self): for fmt in ALL_FORMATS: with self.subTest(fmt=fmt): diff --git a/Misc/NEWS b/Misc/NEWS index 8816ea9..ef9ba7f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -89,6 +89,8 @@ Core and Builtins Library ------- +- Issue #28321: Fixed writing non-BMP characters with binary format in plistlib. + - Issue #28322: Fixed possible crashes when unpickle itertools objects from incorrect pickle data. Based on patch by John Leitch. -- cgit v0.12