diff -r d170844a363f Lib/test/test_ucn.py --- a/Lib/test/test_ucn.py Fri Nov 09 01:09:27 2012 +0200 +++ b/Lib/test/test_ucn.py Fri Nov 09 16:36:22 2012 +0200 @@ -9,6 +9,7 @@ import unittest import unicodedata +import _testcapi from test import support from http.client import HTTPException @@ -215,6 +216,20 @@ str, b"\\NSPACE", 'unicode-escape', 'strict' ) + @unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX, + "needs UINT_MAX < SIZE_MAX") + @support.bigmemtest(size=_testcapi.UINT_MAX + 1 + len(b'\\N{SPACE}') + 1, + memuse=1 + 1, dry_run=False) + def test_issue16335(self, size): + # very very long bogus character name + x = b'\\N{SPACE' + b'x' * (_testcapi.UINT_MAX + 1) + b'}' + 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) diff -r d170844a363f Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Nov 09 01:09:27 2012 +0200 +++ b/Objects/unicodeobject.c Fri Nov 09 16:36:22 2012 +0200 @@ -5561,7 +5561,8 @@ /* found a name. look it up in the unicode database */ message = "unknown Unicode character name"; s++; - if (ucnhash_CAPI->getcode(NULL, start, (int)(s-start-1), + if (s - start - 1 <= INT_MAX && + ucnhash_CAPI->getcode(NULL, start, (int)(s-start-1), &chr, 0)) goto store; }