cpython: 7625866f8127 (original) (raw)
Mercurial > cpython
changeset 81622:7625866f8127 3.2
Issue #16335: Fix integer overflow in unicode-escape decoder. [#16335]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Mon, 21 Jan 2013 11:38:00 +0200 |
parents | 260a9afd999a |
children | 494d341e9143 f84a6c89ccbc |
files | Lib/test/test_ucn.py Objects/unicodeobject.c |
diffstat | 2 files changed, 18 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_ucn.py 16 Objects/unicodeobject.c 3 |
line wrap: on
line diff
--- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -8,6 +8,7 @@ Modified for Python 2.0 by Fredrik Lundh """#" import unittest +import _testcapi from test import support @@ -141,6 +142,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")[](#l1.16)
- def test_issue16335(self):
# very very long bogus character name[](#l1.18)
try:[](#l1.19)
x = b'\\N{SPACE' + b'x' * (_testcapi.UINT_MAX + 1) + b'}'[](#l1.20)
except MemoryError:[](#l1.21)
raise unittest.SkipTest("not enough memory")[](#l1.22)
self.assertEqual(len(x), len(b'\\N{SPACE}') + (_testcapi.UINT_MAX + 1))[](#l1.23)
self.assertRaisesRegex(UnicodeError,[](#l1.24)
'unknown Unicode character name',[](#l1.25)
x.decode, 'unicode-escape'[](#l1.26)
)[](#l1.27)
+ + def test_main(): support.run_unittest(UnicodeNamesTest)
--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3923,7 +3923,8 @@ PyObject PyUnicode_DecodeUnicodeEscape( / 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), &chr))[](#l2.7)
if (s - start - 1 <= INT_MAX &&[](#l2.8)
ucnhash_CAPI->getcode(NULL, start, (int)(s-start-1), &chr))[](#l2.9) goto store;[](#l2.10) }[](#l2.11) }[](#l2.12)