Commit 1e211ff1 authored by Benjamin Peterson's avatar Benjamin Peterson

it suffices to check for PY_SSIZE_T_MAX overflow (#22643)

parent c0e64f50
...@@ -9484,12 +9484,11 @@ case_operation(PyObject *self, ...@@ -9484,12 +9484,11 @@ case_operation(PyObject *self,
kind = PyUnicode_KIND(self); kind = PyUnicode_KIND(self);
data = PyUnicode_DATA(self); data = PyUnicode_DATA(self);
length = PyUnicode_GET_LENGTH(self); length = PyUnicode_GET_LENGTH(self);
if (length > PY_SSIZE_T_MAX / 3 || if (length > PY_SSIZE_T_MAX / (3 * sizeof(Py_UCS4))) {
length > PY_SIZE_MAX / (3 * sizeof(Py_UCS4))) {
PyErr_SetString(PyExc_OverflowError, "string is too long"); PyErr_SetString(PyExc_OverflowError, "string is too long");
return NULL; return NULL;
} }
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * (size_t)length); tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
if (tmp == NULL) if (tmp == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();
newlength = perform(kind, data, length, tmp, &maxchar); newlength = perform(kind, data, length, tmp, &maxchar);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment