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:45:38 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) @@ -1585,6 +1591,14 @@ nd += s - s1; } + /* If there are more than MAX_SIGNIFICANT_DIGITS digits, report + a parse error. */ + if (nd > MAX_SIGNIFICANT_DIGITS) { + if (se) + *se = (char *)s00; + goto parse_error; + } + /* 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. */