Skip to content

Commit fe5e0f8

Browse files
committed
merge 3.4 (#22643)
2 parents e4bf315 + 609a219 commit fe5e0f8

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/test/test_unicode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,11 @@ def test_center(self):
701701
self.assertEqual('x'.center(4, '\U0010FFFF'),
702702
'\U0010FFFFx\U0010FFFF\U0010FFFF')
703703

704+
@unittest.skipUnless(sys.maxsize == 2**31 - 1, "requires 32-bit system")
705+
def test_case_operation_overflow(self):
706+
# Issue #22643
707+
self.assertRaises(OverflowError, ("ü"*(2**32//12 + 1)).upper)
708+
704709
def test_contains(self):
705710
# Testing Unicode contains method
706711
self.assertIn('a', 'abdb')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #22643: Fix integer overflow in Unicode case operations (upper, lower,
14+
title, swapcase, casefold).
15+
1316
- Issue #17636: Circular imports involving relative imports are now
1417
supported.
1518

Objects/unicodeobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9675,6 +9675,11 @@ case_operation(PyObject *self,
96759675
kind = PyUnicode_KIND(self);
96769676
data = PyUnicode_DATA(self);
96779677
length = PyUnicode_GET_LENGTH(self);
9678+
if (length > PY_SSIZE_T_MAX / 3 ||
9679+
length > PY_SIZE_MAX / (3 * sizeof(Py_UCS4))) {
9680+
PyErr_SetString(PyExc_OverflowError, "string is too long");
9681+
return NULL;
9682+
}
96789683
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
96799684
if (tmp == NULL)
96809685
return PyErr_NoMemory();

0 commit comments

Comments
 (0)