Mercurial > cpython-lru_cache-weakref
diff Python/formatter_unicode.c @ 84266:ef5175d08e7e 3.3
Issue #18137: Detect integer overflow on precision in float.__format__() and
complex.__format__().
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Sun, 23 Jun 2013 14:54:30 +0200 |
| parents | c08bcf5302ec |
| children | 4d62a62ba44d 81fef2666ebb |
line wrap: on
line diff
--- a/Python/formatter_unicode.c Sat Jun 22 19:20:54 2013 -0400 +++ b/Python/formatter_unicode.c Sun Jun 23 14:54:30 2013 +0200 @@ -977,7 +977,7 @@ Py_ssize_t n_total; int has_decimal; double val; - Py_ssize_t precision = format->precision; + Py_ssize_t precision; Py_ssize_t default_precision = 6; Py_UCS4 type = format->type; int add_pct = 0; @@ -994,6 +994,12 @@ from a hard-code pseudo-locale */ LocaleInfo locale = STATIC_LOCALE_INFO_INIT; + if (format->precision > INT_MAX) { + PyErr_SetString(PyExc_ValueError, "precision too big"); + goto done; + } + precision = (int)format->precision; + if (format->alternate) flags |= Py_DTSF_ALT; @@ -1127,7 +1133,7 @@ Py_ssize_t n_im_total; int re_has_decimal; int im_has_decimal; - Py_ssize_t precision = format->precision; + int precision; Py_ssize_t default_precision = 6; Py_UCS4 type = format->type; Py_ssize_t i_re; @@ -1155,6 +1161,12 @@ from a hard-code pseudo-locale */ LocaleInfo locale = STATIC_LOCALE_INFO_INIT; + if (format->precision > INT_MAX) { + PyErr_SetString(PyExc_ValueError, "precision too big"); + goto done; + } + precision = (int)format->precision; + /* Zero padding is not allowed. */ if (format->fill_char == '0') { PyErr_SetString(PyExc_ValueError,
