Skip to content

Commit 022db59

Browse files
committed
Issue #17645: convert an assert() into a proper exception in _Py_Mangle().
1 parent 0e7df43 commit 022db59

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Python/compile.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
221221
}
222222
plen = strlen(p);
223223

224-
assert(1 <= PY_SSIZE_T_MAX - nlen);
225-
assert(1 + nlen <= PY_SSIZE_T_MAX - plen);
224+
if (plen + nlen >= PY_SSIZE_T_MAX - 1) {
225+
PyErr_SetString(PyExc_OverflowError,
226+
"private identifier too large to be mangled");
227+
return NULL;
228+
}
226229

227230
ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen);
228231
if (!ident)

0 commit comments

Comments
 (0)