Skip to content

fix(diagnostic): fix excessively large width causing format_args panics #10109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rspack_error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = { workspace = true, features = ["backtrace"] }
cow-utils = { workspace = true }
derive_more = { workspace = true, features = ["debug"] }
futures = { workspace = true }
miette = { version = "7.2.0", features = ["fancy"] }
miette = { version = "7.5.0", features = ["fancy"] }
once_cell = { workspace = true }
owo-colors = "4.0.0"
rspack_cacheable = { workspace = true }
Expand Down
8 changes: 7 additions & 1 deletion crates/rspack_error/src/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@ impl GraphicalReportHandler {
let num_left = vbar_offset - start;
let num_right = end - vbar_offset - 1;
if start < end {
let width = start.saturating_sub(highest);
// CHANGE:
// Rust PR https://github.com/rust-lang/rust/issues/99012 limited format string width and precision to 16 bits, causing panics when dynamic padding exceeds `u16::MAX`.
// This fixes exessively large width that exceeds `u16::MAX` by directly printing exceeded width.
let pre_width = width.saturating_sub(u16::MAX as usize);
underlines.push_str(&format!("{:width$}", "", width = pre_width));
underlines.push_str(
&format!(
"{:width$}{}{}{}",
Expand All @@ -709,7 +715,7 @@ impl GraphicalReportHandler {
chars.underline
},
chars.underline.to_string().repeat(num_right),
width = start.saturating_sub(highest),
width = width.min(u16::MAX as usize),
)
.style(hl.style)
.to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2)
exports[`new code splitting stats output new code splitting stats output/builtin-swc-loader-parse-error should print correct stats for: NewCodeSplittingStatsOutput 1`] = `
ERROR in ./index.ts
× Module build failed:
├─▶ ×
│ │ x Expected '{', got 'error'
├─▶ × x Expected '{', got 'error'
│ │ ,-[<TEST_TOOLS_ROOT>/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts<LINE_COL>]
│ │ 1 | export error;
│ │ : ^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Rspack compiled successfully (27eddb11e03f28d2)
exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for 1`] = `
ERROR in ./index.ts
× Module build failed:
├─▶ ×
│ │ x Expected '{', got 'error'
├─▶ × x Expected '{', got 'error'
│ │ ,-[<TEST_TOOLS_ROOT>/tests/statsOutputCases/builtin-swc-loader-parse-error/index.ts<LINE_COL>]
│ │ 1 | export error;
│ │ : ^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
ERROR in ./index.tsx
× Module build failed:
├─▶ ×
│ │ x Expected a semicolon
├─▶ × x Expected a semicolon
│ │ ,-[<TEST_TOOLS_ROOT>/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx<LINE_COL>]
│ │ 1 | let c = <test>() => {}</test>;
│ │ : ^
│ │ `----
│ │
│ │ x Expression expected
│ │ ,-[<TEST_TOOLS_ROOT>/tests/diagnosticsCases/builtins/recoverable_syntax_error/index.tsx<LINE_COL>]
│ │ 1 | let c = <test>() => {}</test>;
Expand Down
Loading