Issue #14700: Fix buggy overflow checks for large precision and width in new-style and old-style formatting.

This commit is contained in:
Mark Dickinson 2012-10-28 10:18:03 +00:00
parent 579d5cd643
commit fb90c0934c
5 changed files with 45 additions and 20 deletions

View file

@ -9648,7 +9648,7 @@ PyObject *PyUnicode_Format(PyObject *format,
c = *fmt++;
if (c < '0' || c > '9')
break;
if ((width*10) / 10 != width) {
if (width > (PY_SSIZE_T_MAX - ((int)c - '0')) / 10) {
PyErr_SetString(PyExc_ValueError,
"width too big");
goto onError;
@ -9683,7 +9683,7 @@ PyObject *PyUnicode_Format(PyObject *format,
c = *fmt++;
if (c < '0' || c > '9')
break;
if ((prec*10) / 10 != prec) {
if (prec > (INT_MAX - ((int)c - '0')) / 10) {
PyErr_SetString(PyExc_ValueError,
"prec too big");
goto onError;