Skip to content

Commit 609a219

Browse files
committed
merge 3.3 (#22643)
2 parents 95c4a92 + 34ef7c4 commit 609a219

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
@@ -672,6 +672,11 @@ def test_center(self):
672672
self.assertEqual('x'.center(4, '\U0010FFFF'),
673673
'\U0010FFFFx\U0010FFFF\U0010FFFF')
674674

675+
@unittest.skipUnless(sys.maxsize == 2**31 - 1, "requires 32-bit system")
676+
def test_case_operation_overflow(self):
677+
# Issue #22643
678+
self.assertRaises(OverflowError, ("ü"*(2**32//12 + 1)).upper)
679+
675680
def test_contains(self):
676681
# Testing Unicode contains method
677682
self.assertIn('a', 'abdb')

Misc/NEWS

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

14+
- Issue #22643: Fix integer overflow in Unicode case operations (upper, lower,
15+
title, swapcase, casefold).
16+
1417
- Issue #22604: Fix assertion error in debug mode when dividing a complex
1518
number by (nan+0j).
1619

Objects/unicodeobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9651,6 +9651,11 @@ case_operation(PyObject *self,
96519651
kind = PyUnicode_KIND(self);
96529652
data = PyUnicode_DATA(self);
96539653
length = PyUnicode_GET_LENGTH(self);
9654+
if (length > PY_SSIZE_T_MAX / 3 ||
9655+
length > PY_SIZE_MAX / (3 * sizeof(Py_UCS4))) {
9656+
PyErr_SetString(PyExc_OverflowError, "string is too long");
9657+
return NULL;
9658+
}
96549659
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
96559660
if (tmp == NULL)
96569661
return PyErr_NoMemory();

0 commit comments

Comments
 (0)