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 |
fmtvalidates--widthagainstMAX_WIDTH(2500) but applies no upper bound to--tab-width/-T. A large-Tmakescompute_widthreturn a value nearusize::MAX, and every arithmetic consumer of it then overflows.Steps to reproduce
Overflow-checks build (
RUSTFLAGS="-C overflow-checks=on"):linebreak.rs:32:28printf '\ta\tb\tc\n' | fmt -q -T 9223372036854775808linebreak.rs:59:22printf 'aa\n\tbb\n' | fmt -T 18446744073709551615linebreak.rs:114:16printf 'a\tbb\n' | fmt -q -T 18446744073709551615linebreak.rs:123:8printf 'a\tb\n' | fmt -q -T 18446744073709551615linebreak.rs:126:13printf 'aa\n\tbb\n' | fmt -q -c -w 1 -T 18446744073709551615linebreak.rs:281:21printf '\ta\tb\tc\n' | fmt -T 9223372036854775807linebreak.rs:300:33printf 'aa\n\tbb\n' | fmt -c -w 1 -T 18446744073709551615linebreak.rs:307:24printf 'a\tb\n' | fmt -T 18446744073709551615linebreak.rs:485:23printf 'a\tb\n' | fmt -T 9223372036854775807parasplit.rs:234:30printf '\t\t\tx\n' | fmt -T 9223372036854775807parasplit.rs:459:25printf '\ta\tb\tc\n' | fmt -t -T 18446744073709551615