Skip to content

uniq: reject overflowing -f/-s/-w options with trailing garbage - #16158

Open
huuan26 wants to merge 1 commit into
uutils:mainfrom
huuan26:fix/uniq-overflow-trailing-garbage-16122
Open

huuan26 wants to merge 1 commit into
uutils:mainfrom
huuan26:fix/uniq-overflow-trailing-garbage-16122

Conversation

@huuan26

@huuan26 huuan26 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #16122

Summary

When an argument to -f, -s, or -w\ overflowed \usize, \opt_parsed\ unconditionally converted \IntErrorKind::PosOverflow\ into \usize::MAX\ without checking whether the remaining characters in the string were non-digit garbage (e.g. \18446744073709551616x). This caused values with invalid suffixes to be silently accepted.

This PR adds a check \�rg_str.chars().all(|c| c.is_ascii_digit())\ on \IntErrorKind::PosOverflow\ so that:

  • Valid oversized numeric counts (e.g. \18446744073709551616) remain accepted and clamped to \usize::MAX.
  • Malformed inputs with trailing garbage (e.g. \18446744073709551616x) are properly rejected with an invalid argument error, matching GNU \uniq.

Verification

Added test cases in \ ests/by-util/test_uniq.rs\ verifying:

  • -f, -s, and -w\ fail with code 1 when supplied with \18446744073709551616x.
  • Purely numeric overflowing values remain accepted.
    All tests pass.

This branch has not been deployed

No deployments
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.

uniq: overflowing -f/-s/-w values with trailing garbage are silently accepted

1 participant