Skip to content

unexpand: tab-stop increment overflows on a near-maximal ​--tabs=N,+M #13378

Description

@leeewee

unexpand --tabs=N,+M supports an "extended" tab specification where a trailing +M adds one more tab stop M past the last explicit stop N. That extra stop is computed as last + inc with no overflow guard, so a last stop near usize::MAX plus a positive increment overflows. Under overflow checks it aborts; in the default release build it wraps to 0, which then fails the "tab sizes must be ascending" check for the wrong reason.

# overflow-checks build (RUSTFLAGS="-C overflow-checks=on"):
$ printf '\t\n' | unexpand --tabs=18446744073709551615,+1
thread 'main' panicked at src/uu/unexpand/src/unexpand.rs:120:19:
attempt to add with overflow
Aborted (core dumped)
$ echo $?
134

# default release build: no panic; last + inc wraps to 0, so the stop list
# [usize::MAX, 0] is not ascending:
$ printf '\t\n' | unexpand --tabs=18446744073709551615,+1
unexpand: tab sizes must be ascending
$ echo $?
1

18446744073709551615 is usize::MAX on a 64-bit target, so last + inc is usize::MAX + 1.

GNU unexpand handles the same specification by erroring with memory exhausted because it pre-allocates a blank buffer sized to the tab stop:

$ printf '\t\n' | /usr/bin/unexpand --tabs=18446744073709551615,+1
/usr/bin/unexpand: memory exhausted
$ echo $?
1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions