diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-10-15 15:48:41 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-10-15 15:48:41 (GMT) |
commit | 1cbb3fe775c210459f53386b8172f5f2965ee33b (patch) | |
tree | 718e76fe1cc9af45ccae267245787fce8fc913ce | |
parent | fd39a89e0e09de5460626a68e9e443fe0c103c14 (diff) | |
parent | e1bd38c03c16cd27227b3148d2be0ef1ab678448 (diff) | |
download | cpython-1cbb3fe775c210459f53386b8172f5f2965ee33b.zip cpython-1cbb3fe775c210459f53386b8172f5f2965ee33b.tar.gz cpython-1cbb3fe775c210459f53386b8172f5f2965ee33b.tar.bz2 |
merge 3.3 (#22643)
-rw-r--r-- | Lib/test/test_unicode.py | 5 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 5 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 9ae31d1..a72a0cc 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -672,6 +672,11 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual('x'.center(4, '\U0010FFFF'), '\U0010FFFFx\U0010FFFF\U0010FFFF') + @unittest.skipUnless(sys.maxsize == 2**31 - 1, "requires 32-bit system") + def test_case_operation_overflow(self): + # Issue #22643 + self.assertRaises(OverflowError, ("ΓΌ"*(2**32//12 + 1)).upper) + def test_contains(self): # Testing Unicode contains method self.assertIn('a', 'abdb') @@ -11,6 +11,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #22643: Fix integer overflow in Unicode case operations (upper, lower, + title, swapcase, casefold). + - Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j). diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c3f75fd..3132fd4 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9651,6 +9651,11 @@ case_operation(PyObject *self, kind = PyUnicode_KIND(self); data = PyUnicode_DATA(self); length = PyUnicode_GET_LENGTH(self); + if (length > PY_SSIZE_T_MAX / 3 || + length > PY_SIZE_MAX / (3 * sizeof(Py_UCS4))) { + PyErr_SetString(PyExc_OverflowError, "string is too long"); + return NULL; + } tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length); if (tmp == NULL) return PyErr_NoMemory(); |