Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/uu/split/src/filenames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ impl Suffix {
// Auto pre-calculate new suffix length (auto-width) if necessary
if let Strategy::Number(number_type) = strategy {
let chunks = number_type.num_chunks();
let required_length = ((start as u64 + chunks) as f64)
// u128 keeps the sum from overflowing when start is near usize::MAX.
let required_length = ((start as u128 + chunks as u128) as f64)
.log(stype.radix() as f64)
.ceil() as usize;

Expand Down
41 changes: 41 additions & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,47 @@ fn test_suffix_length_req() {
.stderr_only("split: the suffix length needs to be at least 2\n");
}

#[test]
fn test_numeric_suffix_huge_start_requires_suffix_length() {
new_ucmd!()
.args(&[
"-n",
"5",
"--numeric-suffixes=18446744073709551615",
"asciilowercase.txt",
])
.fails()
.stderr_only("split: the suffix length needs to be at least 20\n");
}

#[test]
fn test_hex_suffix_huge_start_requires_suffix_length() {
new_ucmd!()
.args(&[
"-n",
"5",
"--hex-suffixes=ffffffffffffffff",
"asciilowercase.txt",
])
.fails()
.stderr_only("split: the suffix length needs to be at least 16\n");
}

#[test]
fn test_numeric_suffix_huge_chunk_count_requires_suffix_length() {
new_ucmd!()
.args(&[
"-n",
"18446744073709551615",
"--numeric-suffixes=5",
"-a",
"2",
"asciilowercase.txt",
])
.fails()
.stderr_only("split: the suffix length needs to be at least 20\n");
}

#[test]
fn test_large_suffix_length_is_rejected() {
new_ucmd!()
Expand Down
Loading