@@ -977,7 +977,7 @@ format_float_internal(PyObject *value,
977977 Py_ssize_t n_total ;
978978 int has_decimal ;
979979 double val ;
980- Py_ssize_t precision = format -> precision ;
980+ Py_ssize_t precision ;
981981 Py_ssize_t default_precision = 6 ;
982982 Py_UCS4 type = format -> type ;
983983 int add_pct = 0 ;
@@ -994,6 +994,12 @@ format_float_internal(PyObject *value,
994994 from a hard-code pseudo-locale */
995995 LocaleInfo locale = STATIC_LOCALE_INFO_INIT ;
996996
997+ if (format -> precision > INT_MAX ) {
998+ PyErr_SetString (PyExc_ValueError , "precision too big" );
999+ goto done ;
1000+ }
1001+ precision = (int )format -> precision ;
1002+
9971003 if (format -> alternate )
9981004 flags |= Py_DTSF_ALT ;
9991005
@@ -1127,7 +1133,7 @@ format_complex_internal(PyObject *value,
11271133 Py_ssize_t n_im_total ;
11281134 int re_has_decimal ;
11291135 int im_has_decimal ;
1130- Py_ssize_t precision = format -> precision ;
1136+ int precision ;
11311137 Py_ssize_t default_precision = 6 ;
11321138 Py_UCS4 type = format -> type ;
11331139 Py_ssize_t i_re ;
@@ -1155,6 +1161,12 @@ format_complex_internal(PyObject *value,
11551161 from a hard-code pseudo-locale */
11561162 LocaleInfo locale = STATIC_LOCALE_INFO_INIT ;
11571163
1164+ if (format -> precision > INT_MAX ) {
1165+ PyErr_SetString (PyExc_ValueError , "precision too big" );
1166+ goto done ;
1167+ }
1168+ precision = (int )format -> precision ;
1169+
11581170 /* Zero padding is not allowed. */
11591171 if (format -> fill_char == '0' ) {
11601172 PyErr_SetString (PyExc_ValueError ,
0 commit comments