Skip to content

Commit 1e211ff

Browse files
committed
it suffices to check for PY_SSIZE_T_MAX overflow (#22643)
1 parent c0e64f5 commit 1e211ff

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Objects/unicodeobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9484,12 +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))) {
9487+
if (length > PY_SSIZE_T_MAX / (3 * sizeof(Py_UCS4))) {
94899488
PyErr_SetString(PyExc_OverflowError, "string is too long");
94909489
return NULL;
94919490
}
9492-
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * (size_t)length);
9491+
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
94939492
if (tmp == NULL)
94949493
return PyErr_NoMemory();
94959494
newlength = perform(kind, data, length, tmp, &maxchar);

0 commit comments

Comments
 (0)