@@ -982,7 +982,7 @@ format_float_internal(PyObject *value,
982982 Py_ssize_t n_total ;
983983 int has_decimal ;
984984 double val ;
985- Py_ssize_t precision = format -> precision ;
985+ Py_ssize_t precision ;
986986 Py_ssize_t default_precision = 6 ;
987987 Py_UCS4 type = format -> type ;
988988 int add_pct = 0 ;
@@ -999,6 +999,12 @@ format_float_internal(PyObject *value,
999999 from a hard-code pseudo-locale */
10001000 LocaleInfo locale = STATIC_LOCALE_INFO_INIT ;
10011001
1002+ if (format -> precision > INT_MAX ) {
1003+ PyErr_SetString (PyExc_ValueError , "precision too big" );
1004+ goto done ;
1005+ }
1006+ precision = (int )format -> precision ;
1007+
10021008 if (format -> alternate )
10031009 flags |= Py_DTSF_ALT ;
10041010
@@ -1132,7 +1138,7 @@ format_complex_internal(PyObject *value,
11321138 Py_ssize_t n_im_total ;
11331139 int re_has_decimal ;
11341140 int im_has_decimal ;
1135- Py_ssize_t precision = format -> precision ;
1141+ int precision ;
11361142 Py_ssize_t default_precision = 6 ;
11371143 Py_UCS4 type = format -> type ;
11381144 Py_ssize_t i_re ;
@@ -1160,6 +1166,12 @@ format_complex_internal(PyObject *value,
11601166 from a hard-code pseudo-locale */
11611167 LocaleInfo locale = STATIC_LOCALE_INFO_INIT ;
11621168
1169+ if (format -> precision > INT_MAX ) {
1170+ PyErr_SetString (PyExc_ValueError , "precision too big" );
1171+ goto done ;
1172+ }
1173+ precision = (int )format -> precision ;
1174+
11631175 /* Zero padding is not allowed. */
11641176 if (format -> fill_char == '0' ) {
11651177 PyErr_SetString (PyExc_ValueError ,
0 commit comments