From: Serhiy Storchaka Date: Sat, 19 Jan 2013 21:35:46 +0000 (+0200) Subject: Issue #15989: Fix possible integer overflow in str formatting as in unicode formatting. X-Git-Tag: v2.7.4rc1~164^2~60 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=926f3a37de4def3e891f1533bd2edcf292aa74d2;p=python Issue #15989: Fix possible integer overflow in str formatting as in unicode formatting. --- diff --git a/Objects/stringobject.c b/Objects/stringobject.c index c6f2220bbf..b9809a276b 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4355,7 +4355,9 @@ PyString_Format(PyObject *format, PyObject *args) "* wants int"); goto error; } - width = PyInt_AsLong(v); + width = PyInt_AsSsize_t(v); + if (width == -1 && PyErr_Occurred()) + goto error; if (width < 0) { flags |= F_LJUST; width = -width; @@ -4392,7 +4394,9 @@ PyString_Format(PyObject *format, PyObject *args) "* wants int"); goto error; } - prec = PyInt_AsLong(v); + prec = _PyInt_AsInt(v); + if (prec == -1 && PyErr_Occurred()) + goto error; if (prec < 0) prec = 0; if (--fmtcnt >= 0)