summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-06-11 21:46:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-06-11 21:46:32 (GMT)
commitcc0cfd357611c69a99841f21affa73e829416789 (patch)
treee7c632a1e6fad23b9e40ea05e384a86c428468bd /Lib/test/test_codecs.py
parent0277555ff236b0b781657516d7cb8851adeae8bb (diff)
downloadcpython-cc0cfd357611c69a99841f21affa73e829416789.zip
cpython-cc0cfd357611c69a99841f21affa73e829416789.tar.gz
cpython-cc0cfd357611c69a99841f21affa73e829416789.tar.bz2
Merged revisions 81907 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81907 | antoine.pitrou | 2010-06-11 23:42:26 +0200 (ven., 11 juin 2010) | 5 lines Issue #8941: decoding big endian UTF-32 data in UCS-2 builds could crash the interpreter with characters outside the Basic Multilingual Plane (higher than 0x10000). ........
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 7de1ed5..911d58f 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -353,6 +353,16 @@ class UTF32Test(ReadTest):
self.check_state_handling_decode(self.encoding,
"spamspam", self.spambe)
+ def test_issue8941(self):
+ # Issue #8941: insufficient result allocation when decoding into
+ # surrogate pairs on UCS-2 builds.
+ encoded_le = b'\xff\xfe\x00\x00' + b'\x00\x00\x01\x00' * 1024
+ self.assertEqual('\U00010000' * 1024,
+ codecs.utf_32_decode(encoded_le)[0])
+ encoded_be = b'\x00\x00\xfe\xff' + b'\x00\x01\x00\x00' * 1024
+ self.assertEqual('\U00010000' * 1024,
+ codecs.utf_32_decode(encoded_be)[0])
+
class UTF32LETest(ReadTest):
encoding = "utf-32-le"
@@ -386,6 +396,13 @@ class UTF32LETest(ReadTest):
self.assertRaises(UnicodeDecodeError, codecs.utf_32_le_decode,
b"\xff", "strict", True)
+ def test_issue8941(self):
+ # Issue #8941: insufficient result allocation when decoding into
+ # surrogate pairs on UCS-2 builds.
+ encoded = b'\x00\x00\x01\x00' * 1024
+ self.assertEqual('\U00010000' * 1024,
+ codecs.utf_32_le_decode(encoded)[0])
+
class UTF32BETest(ReadTest):
encoding = "utf-32-be"
@@ -419,6 +436,14 @@ class UTF32BETest(ReadTest):
self.assertRaises(UnicodeDecodeError, codecs.utf_32_be_decode,
b"\xff", "strict", True)
+ def test_issue8941(self):
+ # Issue #8941: insufficient result allocation when decoding into
+ # surrogate pairs on UCS-2 builds.
+ encoded = b'\x00\x01\x00\x00' * 1024
+ self.assertEqual('\U00010000' * 1024,
+ codecs.utf_32_be_decode(encoded)[0])
+
+
class UTF16Test(ReadTest):
encoding = "utf-16"