summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-21 09:44:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-21 09:44:40 (GMT)
commit6481bfb2b5c917041f062da8ebcc7bd7b7727945 (patch)
tree0bfde20393dc4b3514d2734b46bd64354b3b2fdf /Lib/test
parenta12ff2c682df32c58fae23eef27ab0273f7b8659 (diff)
parentc35f3a9f619d0d4abd43d16ddc4767e2a30c3dce (diff)
downloadcpython-6481bfb2b5c917041f062da8ebcc7bd7b7727945.zip
cpython-6481bfb2b5c917041f062da8ebcc7bd7b7727945.tar.gz
cpython-6481bfb2b5c917041f062da8ebcc7bd7b7727945.tar.bz2
Issue #16335: Fix integer overflow in unicode-escape decoder.
Diffstat (limited to 'Lib/test')
-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 319c213..13aebaa 100644
--- a/Lib/test/test_ucn.py
+++ b/Lib/test/test_ucn.py
@@ -9,6 +9,7 @@ Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
import unittest
import unicodedata
+import _testcapi
from test import support
from http.client import HTTPException
@@ -215,6 +216,21 @@ class UnicodeNamesTest(unittest.TestCase):
str, b"\\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' * (_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():
support.run_unittest(UnicodeNamesTest)