summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-10-15 11:47:36 -0400
committerBenjamin Peterson <benjamin@python.org>2014-10-15 11:47:36 -0400
commit89c362b60dffb4c5d1a1bdd6fc22097d1d92e3a5 (patch)
tree60ca25c40f3af1f35a379d77b4ea10898759970f /Objects
parent385b5f2a01b61226c9d8d416459684a6537d563f (diff)
downloadcpython-89c362b60dffb4c5d1a1bdd6fc22097d1d92e3a5.tar.gz
fix integer overflow in unicode case operations (closes #22643)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 1ce5caafdc..35da457530 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9484,6 +9484,11 @@ case_operation(PyObject *self,
kind = PyUnicode_KIND(self);
data = PyUnicode_DATA(self);
length = PyUnicode_GET_LENGTH(self);
+ if (length > PY_SSIZE_T_MAX / 3 ||
+ length > PY_SIZE_MAX / (3 * sizeof(Py_UCS4))) {
+ PyErr_SetString(PyExc_OverflowError, "string is too long");
+ return NULL;
+ }
tmp = PyMem_MALLOC(sizeof(Py_UCS4) * 3 * length);
if (tmp == NULL)
return PyErr_NoMemory();