diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py index 15cee0d3a44..2c801797cdd 100644 --- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -1463,7 +1463,6 @@ def test_format_huge_precision(self): with self.assertRaises(ValueError): result = format(2.34, format_string) - @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: ValueError not raised def test_format_huge_width(self): format_string = "{}f".format(sys.maxsize + 1) with self.assertRaises(ValueError): diff --git a/crates/common/src/format.rs b/crates/common/src/format.rs index 9b769a038e7..f5e09bb1e91 100644 --- a/crates/common/src/format.rs +++ b/crates/common/src/format.rs @@ -315,6 +315,11 @@ impl FormatSpec { let (alternate_form, text) = parse_alternate_form(text); let (zero, text) = parse_zero(text); let (width, text) = parse_number(text)?; + if let Some(w) = width + && w > i32::MAX as usize + { + return Err(FormatSpecError::DecimalDigitsTooMany); + } let (grouping_option, text) = FormatGrouping::parse(text); if let Some(grouping) = &grouping_option { Self::validate_separator(grouping, text)?;