summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-06-11 21:48:34 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-06-11 21:48:34 (GMT)
commit6107a688eed14f6c886679ed723448cc531194c2 (patch)
treef1e0ee676386a3490d1bb464c4b7ba5106515813 /Lib/test/test_codecs.py
parent4a3acca7c1f85946ac7526e303956dc03acd91fe (diff)
downloadcpython-6107a688eed14f6c886679ed723448cc531194c2.zip
cpython-6107a688eed14f6c886679ed723448cc531194c2.tar.gz
cpython-6107a688eed14f6c886679ed723448cc531194c2.tar.bz2
Merged revisions 81908 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r81908 | antoine.pitrou | 2010-06-11 23:46:32 +0200 (ven., 11 juin 2010) | 11 lines 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 5db5dcb..5ee2d9f 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -354,6 +354,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"
@@ -387,6 +397,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"
@@ -420,6 +437,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"