summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
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"