File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -661,6 +661,11 @@ def test_center(self):
661661 self .assertEqual ('x' .center (4 , '\U0010FFFF ' ),
662662 '\U0010FFFF x\U0010FFFF \U0010FFFF ' )
663663
664+ @unittest .skipUnless (sys .maxsize == 2 ** 31 - 1 , "requires 32-bit system" )
665+ def test_case_operation_overflow (self ):
666+ # Issue #22643
667+ self .assertRaises (OverflowError , ("ü" * (2 ** 32 // 12 + 1 )).upper )
668+
664669 def test_contains (self ):
665670 # Testing Unicode contains method
666671 self .assertIn ('a' , 'abdb' )
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.3.6?
1010Core and Builtins
1111-----------------
1212
13+ - Issue #22643: Fix integer overflow in Unicode case operations (upper, lower,
14+ title, swapcase, casefold).
15+
1316- Issue #22518: Fixed integer overflow issues in "backslashreplace",
1417 "xmlcharrefreplace", and "surrogatepass" error handlers.
1518
Original file line number Diff line number Diff line change @@ -9484,6 +9484,11 @@ case_operation(PyObject *self,
94849484 kind = PyUnicode_KIND (self );
94859485 data = PyUnicode_DATA (self );
94869486 length = PyUnicode_GET_LENGTH (self );
9487+ if (length > PY_SSIZE_T_MAX / 3 ||
9488+ length > PY_SIZE_MAX / (3 * sizeof (Py_UCS4 ))) {
9489+ PyErr_SetString (PyExc_OverflowError , "string is too long" );
9490+ return NULL ;
9491+ }
94879492 tmp = PyMem_MALLOC (sizeof (Py_UCS4 ) * 3 * length );
94889493 if (tmp == NULL )
94899494 return PyErr_NoMemory ();
You can’t perform that action at this time.
0 commit comments