Issue #14700: Fix buggy overflow checks for large precision and width in new-style and old-style formatting.
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 39fa740..152ea21 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -4369,7 +4369,7 @@
c = Py_CHARMASK(*fmt++);
if (!isdigit(c))
break;
- if ((width*10) / 10 != width) {
+ if (width > (PY_SSIZE_T_MAX - ((int)c - '0')) / 10) {
PyErr_SetString(
PyExc_ValueError,
"width too big");
@@ -4404,7 +4404,7 @@
c = Py_CHARMASK(*fmt++);
if (!isdigit(c))
break;
- if ((prec*10) / 10 != prec) {
+ if (prec > (INT_MAX - ((int)c - '0')) / 10) {
PyErr_SetString(
PyExc_ValueError,
"prec too big");