Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a14c4bb

Browse files
committed
Check whether the strlen() result overflows Py_ssize_t.
1 parent 9bc4712 commit a14c4bb

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Objects/unicodeobject.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,11 @@ PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
396396
PyObject *PyUnicode_FromString(const char *u)
397397
{
398398
PyUnicodeObject *unicode;
399-
Py_ssize_t size = strlen(u);
399+
size_t size = strlen(u);
400+
if (size > PY_SSIZE_T_MAX) {
401+
PyErr_SetString(PyExc_OverflowError, "input too long");
402+
return NULL;
403+
}
400404

401405
/* If the Unicode data is known at construction time, we can apply
402406
some optimizations which share commonly used objects. */

0 commit comments

Comments
 (0)