Skip to content

split: reject a zero chunk count for -n l/N and r/N#12613

Merged
cakebaker merged 1 commit into
uutils:mainfrom
leeewee:split-reject-zero-chunks
Jun 18, 2026
Merged

split: reject a zero chunk count for -n l/N and r/N#12613
cakebaker merged 1 commit into
uutils:mainfrom
leeewee:split-reject-zero-chunks

Conversation

@leeewee

@leeewee leeewee commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #12612

split -n l/0 and split -n r/0 aborted with a divide-by-zero panic: NumberType::from rejected a zero count for the bare N/K/N forms but not for l/N and r/N, so num_chunks == 0 reached the chunk arithmetic.

Reject num_chunks == 0 in those two branches too, returning NumberTypeError::NumberOfChunks like the bare-N form — now matching GNU (split: invalid number of chunks: '0', exit 1). Adds unit + integration regression tests.

`split -n l/0` and `split -n r/0` aborted with a divide-by-zero panic
(`num_bytes / num_chunks` in `n_chunks_by_line` and `i % num_chunks` in
`n_chunks_by_line_round_robin`). `NumberType::from` validated `N > 0` for
the bare `N` / `K/N` forms but not for the `l/N` and `r/N` forms, so a
zero count reached the chunk arithmetic.

Reject `num_chunks == 0` in those two branches, returning
`NumberTypeError::NumberOfChunks` like the bare-`N` form, which matches
GNU (`split: invalid number of chunks: '0'`, exit 1) and validates up
front rather than crashing while reading input.
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/pr/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/unexpand/bounded-memory is now passing!

@cakebaker cakebaker merged commit 8464759 into uutils:main Jun 18, 2026
174 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

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.

split panics (divide-by-zero) on a zero chunk count in -n l/0 and -n r/0

2 participants