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

Skip to content

Commit 926f3a3

Browse files
Issue python#15989: Fix possible integer overflow in str formatting as in unicode formatting.
1 parent 6b78bff commit 926f3a3

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Objects/stringobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,7 +4355,9 @@ PyString_Format(PyObject *format, PyObject *args)
43554355
"* wants int");
43564356
goto error;
43574357
}
4358-
width = PyInt_AsLong(v);
4358+
width = PyInt_AsSsize_t(v);
4359+
if (width == -1 && PyErr_Occurred())
4360+
goto error;
43594361
if (width < 0) {
43604362
flags |= F_LJUST;
43614363
width = -width;
@@ -4392,7 +4394,9 @@ PyString_Format(PyObject *format, PyObject *args)
43924394
"* wants int");
43934395
goto error;
43944396
}
4395-
prec = PyInt_AsLong(v);
4397+
prec = _PyInt_AsInt(v);
4398+
if (prec == -1 && PyErr_Occurred())
4399+
goto error;
43964400
if (prec < 0)
43974401
prec = 0;
43984402
if (--fmtcnt >= 0)

0 commit comments

Comments
 (0)