Skip to content
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
4 changes: 3 additions & 1 deletion src/uu/unexpand/src/unexpand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ fn parse_tabstops(s: &str) -> Result<TabConfig, ParseError> {
// Only add an extra tab stop if increment is non-zero
if let Some(inc) = increment_size.filter(|&i| i > 0) {
let last = *nums.last().unwrap();
nums.push(last + inc);
// Reject a last stop + increment that overflows usize instead of panicking/wrapping (matches GNU).
let next = last.checked_add(inc).ok_or(ParseError::TabSizeTooLarge)?;
nums.push(next);
}

if let (false, _) = nums
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_unexpand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ fn test_tabs_shortcut_with_too_large_size() {
new_ucmd!().arg(arg).fails().stderr_contains(expected_error);
}

#[test]
fn test_extended_tabstop_increment_overflow() {
// `--tabs=N,+M` with N near usize::MAX must be rejected, not overflow the N+M stop.
let arg = format!("--tabs={},+1", usize::MAX);
new_ucmd!()
.arg(arg)
.fails()
.stderr_contains("tab stop value is too large");
}

#[test]
fn test_is_directory() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading