diff Objects/stringobject.c @ 80014:21fb1767e185 2.7

Issue #14700: Fix buggy overflow checks for large precision and width in new-style and old-style formatting.
author Mark Dickinson <mdickinson@enthought.com>
date Sun, 28 Oct 2012 10:00:46 +0000
parents 3b484f53f91b
children 80cfd4caa726
line wrap: on
line diff
--- a/Objects/stringobject.c	Sun Oct 28 10:51:35 2012 +0100
+++ b/Objects/stringobject.c	Sun Oct 28 10:00:46 2012 +0000
@@ -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");