From 55bff8919031093dad249be793d24c66956d8af3 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 6 Apr 2013 21:21:04 +0200 Subject: [PATCH] Issue #17645: convert an assert() into a proper exception in _Py_Mangle(). --- Python/compile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index 3cf71ef09e2..0a8f58e692d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -248,8 +248,11 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident) } plen -= ipriv; - assert(1 <= PY_SSIZE_T_MAX - nlen); - assert(1 + nlen <= PY_SSIZE_T_MAX - plen); + if (plen + nlen >= PY_SSIZE_T_MAX - 1) { + PyErr_SetString(PyExc_OverflowError, + "private identifier too large to be mangled"); + return NULL; + } maxchar = PyUnicode_MAX_CHAR_VALUE(ident); if (PyUnicode_MAX_CHAR_VALUE(privateobj) > maxchar)