diff -r cc0fc4e9b494 Python/dtoa.c --- a/Python/dtoa.c Sat Nov 23 21:14:42 2013 +0200 +++ b/Python/dtoa.c Sat Nov 23 19:58:58 2013 +0000 @@ -207,6 +207,12 @@ #define MAX_ABS_EXP 19999U #endif +/* maximum permitted number of significant digits in the strtod input. + This should be chosen to safely fit into an int. */ +#ifndef MAX_SIGNIFICANT_DIGITS +#define MAX_SIGNIFICANT_DIGITS 2000000000 +#endif + /* The following definition of Storeinc is appropriate for MIPS processors. * An alternative that might be better on some machines is * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) @@ -1538,6 +1544,7 @@ Long L; BCinfo bc; Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; + size_t pnd, pnd0; dval(&rv) = 0.; @@ -1566,25 +1573,35 @@ s0 = s1 = s; while ('0' <= c && c <= '9') c = *++s; - nd0 = nd = s - s1; + pnd0 = pnd = s - s1; /* Parse decimal point and following digits. */ if (c == '.') { c = *++s; - if (!nd) { + if (!pnd) { s1 = s; while (c == '0') c = *++s; lz = lz || s != s1; - nd0 -= s - s1; + pnd0 -= s - s1; s0 = s; } s1 = s; while ('0' <= c && c <= '9') c = *++s; - nd += s - s1; + pnd += s - s1; } + /* If there are more than MAX_SIGNIFICANT_DIGITS digits, report + a parse error. */ + if (pnd > MAX_SIGNIFICANT_DIGITS) { + if (se) + *se = (char *)s00; + goto parse_error; + } + nd = (int)pnd; + nd0 = (int)pnd0; + /* Now lz is true if and only if there were leading zero digits, and nd gives the total number of digits ignoring leading zeros. A valid input must have at least one digit. */