diff: `-y --tabsize=<huge>` overflows the column arithmetic (overflow-checks only)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Start in src/side_diff.rs at SideDiffConfig::new and inspect the arithmetic around line 85, including how --tabsize reaches tab_size. Reproduce the provided command with overflow checks enabled and verify that extreme and zero tab sizes no longer panic or produce invalid layout widths.
Written by the indexing model from the issue text.
Description
SideDiffConfig::new (src/side_diff.rs) computes the side-by-side column layout with signed arithmetic on the --tabsize value:
let w = full_width as isize;
let t = tab_size as isize;
let t_plus_g = t + GUTTER_WIDTH_MIN as isize; // <-- side_diff.rs:85: overflows
let unaligned_off = (w >> 1) + (t_plus_g >> 1) + (w & t_plus_g & 1);
let off = unaligned_off - unaligned_off % t; // (also % by t, and t can be 0)
--tabsize is parsed into tab_size: usize with no upper bound. A value near isize::MAX makes t + GUTTER_WIDTH_MIN (GUTTER_WIDTH_MIN == 3) overflow isize. Under -C overflow-checks=on this aborts (exit 134); in the default release build it wraps to a bogus value and the layout math silently produces garbage widths.
$ printf 'a\n' > f1; printf 'b\n' > f2
$ diff -y --tabsize=9223372036854775805 f1 f2 # overflow-checks build
thread 'main' panicked at src/side_diff.rs:85:24:
attempt to add with overflow
$ echo $?
134
- Dominant language
- Rust
- Stars
- 276
- Forks
- 39
- Avg merge
- 3h 27m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uutils/diffutils
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 64/100
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
All issues in uutils/diffutils
Similar issues
-
risk:low runtime status:in-progress type:test
Difficulty 1/5 Under an hour Newbie friendliness 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
EricSpencer00/Resilient#4835 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bisq-network/bisq-musig#204 ·
-
agent:ready documentation
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
cesarferreira/stax#890 ·