Skip to content

fix: csplit --suffix-format huge field width panics instead of erroring#13256

Open
mvanhorn wants to merge 1 commit into
uutils:mainfrom
mvanhorn:fix/12763-csplit-suffix-format-width-panic
Open

fix: csplit --suffix-format huge field width panics instead of erroring#13256
mvanhorn wants to merge 1 commit into
uutils:mainfrom
mvanhorn:fix/12763-csplit-suffix-format-width-panic

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

csplit no longer panics when --suffix-format requests an enormous field width. A format like --suffix-format=%0999999999d now returns a clean error instead of aborting with a Rust panic, because the split-name formatter propagates the formatting error rather than unwrapping it.

Why this matters

Issue #12763 reports that csplit panics on a --suffix-format with a very large field width. SplitName::get used write!/format! and unwrapped the result; for a pathological width the formatter allocation/formatting failed and the unwrap turned that into a panic, crashing the utility instead of reporting a usage error the way GNU csplit does.

The formatter now returns io::Result<String> and the caller surfaces a proper csplit error, so an unusable suffix format is rejected with a message and a non-zero exit rather than a panic.

Testing

cargo test -p uu_csplit passes, including a new test_csplit case asserting that a huge --suffix-format width errors out (non-zero exit, no panic) instead of crashing. cargo clippy -p uu_csplit is clean.

Fixes #12763

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 331 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing mvanhorn:fix/12763-csplit-suffix-format-width-panic (24b9c6a) with main (dad997e)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/rm/isatty (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but could you please rebase it ? thanks

@mvanhorn mvanhorn force-pushed the fix/12763-csplit-suffix-format-width-panic branch from d65969e to 24b9c6a Compare July 6, 2026 17:31
@mvanhorn

mvanhorn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main. There were a couple of real conflicts from the csplit error-type refactor (the new strip_errno IoError with #[from]): kept your strip_errno formatting but dropped #[from], since this fix needs a custom From<io::Error> that maps OutOfMemory to a MemoryExhausted error (that's what turns a huge --suffix-format width into a clean error instead of a panic). cargo build, cargo test -p uu_csplit (37 pass), fmt and clippy all clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

csplit: --suffix-format with a huge field width panics (Result::unwrap on a formatter error)

2 participants