diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-06-23 12:55:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-06-23 12:55:43 (GMT) |
commit | 2ab07f01a4787336600b95cdf0312a9e6e00f34e (patch) | |
tree | e94f8996b44832e6a36078fd4eb40b39a63faea7 /Python | |
parent | c6ebd16a203b84de020fb236f32e8c58db92718d (diff) | |
parent | 2f084ecfe78472b6a1a6c8b07472672176d4f848 (diff) | |
download | cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.zip cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.tar.gz cpython-2ab07f01a4787336600b95cdf0312a9e6e00f34e.tar.bz2 |
(Merge 3.3) Issue #18137: Detect integer overflow on precision in
float.__format__() and complex.__format__().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/formatter_unicode.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index bb173d9..aac85b3 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -982,7 +982,7 @@ format_float_internal(PyObject *value, 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; @@ -999,6 +999,12 @@ format_float_internal(PyObject *value, 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; @@ -1132,7 +1138,7 @@ format_complex_internal(PyObject *value, 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; @@ -1160,6 +1166,12 @@ format_complex_internal(PyObject *value, 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, |