summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ucn.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-21 09:48:24 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-21 09:48:24 (GMT)
commit1d3acd4b59b1685d3b6f58e86ef13b48a9c248bb (patch)
treeb33ffcd829b2eecc7970c760af0faf0540612c06 /Lib/test/test_ucn.py
parentb357db885c8c20bf085d6b65892a618a51b4e1b0 (diff)
downloadcpython-1d3acd4b59b1685d3b6f58e86ef13b48a9c248bb.zip
cpython-1d3acd4b59b1685d3b6f58e86ef13b48a9c248bb.tar.gz
cpython-1d3acd4b59b1685d3b6f58e86ef13b48a9c248bb.tar.bz2
Issue #16335: Fix integer overflow in unicode-escape decoder.
Diffstat (limited to 'Lib/test/test_ucn.py')
-rw-r--r--Lib/test/test_ucn.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py
index 775044b..1d303dc 100644
--- a/Lib/test/test_ucn.py
+++ b/Lib/test/test_ucn.py
@@ -8,6 +8,7 @@ Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
"""#"
import unittest
+import _testcapi
from test import test_support
@@ -137,6 +138,21 @@ class UnicodeNamesTest(unittest.TestCase):
unicode, "\\NSPACE", 'unicode-escape', 'strict'
)
+ @unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX,
+ "needs UINT_MAX < SIZE_MAX")
+ def test_issue16335(self):
+ # very very long bogus character name
+ try:
+ x = b'\\N{SPACE' + b'x' * int(_testcapi.UINT_MAX + 1) + b'}'
+ except MemoryError:
+ raise unittest.SkipTest("not enough memory")
+ self.assertEqual(len(x), len(b'\\N{SPACE}') + (_testcapi.UINT_MAX + 1))
+ self.assertRaisesRegex(UnicodeError,
+ 'unknown Unicode character name',
+ x.decode, 'unicode-escape'
+ )
+
+
def test_main():
test_support.run_unittest(UnicodeNamesTest)