diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
Research direction
Start in src/params.rs around the width and tabsize regexes at lines 62-63, then inspect the argument handling around line 116. Reproduce with the non-UTF-8 --width argument shown in the issue and verify that the argument is treated as a file operand rather than causing a panic or being accepted as an option; also check the xyz--width=5 case.
Written by the indexing model from the issue text.
Description
Steps to reproduce
$ printf 'a\nb\nc\n' > A; printf 'a\nX\nc\n' > B
$ diffutils diff $'\xff--width=5' A B
thread 'main' panicked at src/params.rs:116:45:
called `Result::unwrap()` on an `Err` value: "\xFF--width=5"
$ echo $?
134
diff aborts (panic, exit 134) when given a non-UTF-8 argument whose lossy form ends in --width=<digits> — e.g. an argument with a leading invalid byte like $'\xff--width=5'.
Expected behavior
Match GNU: the unrecognized argument is a file operand; with three operands diff reports the extra operand and exits 2.
$ /usr/bin/diff $'\xff--width=5' A B
diff: extra operand 'B'
$ echo $?
2
Root cause
The --width regex lacks a start anchor, unlike the sibling --tabsize one:
// src/params.rs:62-63
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap(); // anchored — safe
let width_re = Regex::new(r"--width=(?P<long>\d+)$").unwrap(); // no leading ^
// src/params.rs:115-116
if width_re.is_match(param.to_string_lossy().as_ref()) { // matches lossy form
let param = param.into_string().unwrap(); // line 116: Err on non-UTF-8
to_string_lossy() maps invalid bytes to U+FFFD, so a non-UTF-8 argument whose tail is --width=N still matches; into_string() then fails on the real bytes.
Fix: anchor the regex at the start (^--width=…$, matching tabsize_re), and/or match on the bytes / avoid into_string().unwrap() so a non-UTF-8 argument falls through to the operand path. (The unanchored regex also makes diff xyz--width=5 silently accept a width option instead of treating it as a filename — same root cause, non-panic symptom.)
Found by our static analysis tooling.
- 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 70/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
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100