changeset: 104284:381ef0f08f89 branch: 3.5 parent: 104279:b674fd340a23 user: Serhiy Storchaka date: Tue Oct 04 20:04:30 2016 +0300 files: Lib/plistlib.py Lib/test/test_plistlib.py Misc/NEWS description: Issue #28321: Fixed writing non-BMP characters with binary format in plistlib. diff -r b674fd340a23 -r 381ef0f08f89 Lib/plistlib.py --- a/Lib/plistlib.py Tue Oct 04 18:23:55 2016 +0300 +++ b/Lib/plistlib.py Tue Oct 04 20:04:30 2016 +0300 @@ -918,7 +918,7 @@ 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 -r b674fd340a23 -r 381ef0f08f89 Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py Tue Oct 04 18:23:55 2016 +0300 +++ b/Lib/test/test_plistlib.py Tue Oct 04 20:04:30 2016 +0300 @@ -361,6 +361,13 @@ 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 -r b674fd340a23 -r 381ef0f08f89 Misc/NEWS --- a/Misc/NEWS Tue Oct 04 18:23:55 2016 +0300 +++ b/Misc/NEWS Tue Oct 04 20:04:30 2016 +0300 @@ -89,6 +89,8 @@ 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.