Skip to content

fmt: --tab-width/-T has no upper bound — arithmetic overflow aborts at multiple sites (exit 134) #14460

Description

@leeewee

fmt validates --width against MAX_WIDTH (2500) but applies no upper bound to --tab-width/-T. A large -T makes compute_width return a value near usize::MAX, and every arithmetic consumer of it then overflows.

Steps to reproduce

Overflow-checks build (RUSTFLAGS="-C overflow-checks=on"):

$ printf '\thello world' | fmt -T 18446744073709551615
thread 'main' panicked at src/uu/fmt/src/linebreak.rs:59:22:
attempt to add with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134
site overflow reproducer
linebreak.rs:32:28 multiply printf '\ta\tb\tc\n' | fmt -q -T 9223372036854775808
linebreak.rs:59:22 add printf 'aa\n\tbb\n' | fmt -T 18446744073709551615
linebreak.rs:114:16 add printf 'a\tbb\n' | fmt -q -T 18446744073709551615
linebreak.rs:123:8 add printf 'a\tb\n' | fmt -q -T 18446744073709551615
linebreak.rs:126:13 add printf 'aa\n\tbb\n' | fmt -q -c -w 1 -T 18446744073709551615
linebreak.rs:281:21 subtract printf '\ta\tb\tc\n' | fmt -T 9223372036854775807
linebreak.rs:300:33 add printf 'aa\n\tbb\n' | fmt -c -w 1 -T 18446744073709551615
linebreak.rs:307:24 add printf 'a\tb\n' | fmt -T 18446744073709551615
linebreak.rs:485:23 subtract printf 'a\tb\n' | fmt -T 9223372036854775807
parasplit.rs:234:30 multiply printf '\t\t\tx\n' | fmt -T 9223372036854775807
parasplit.rs:459:25 add printf '\ta\tb\tc\n' | fmt -t -T 18446744073709551615

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

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions