Title: diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N` · Issue #247 · uutils/diffutils · GitHub
Open Graph Title: diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N` · Issue #247 · uutils/diffutils
X Title: diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N` · Issue #247 · uutils/diffutils
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 abo...
Open Graph 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...
X 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: calle...
Opengraph URL: https://github.com/uutils/diffutils/issues/247
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N`","articleBody":"## Steps to reproduce\n\n```console\n$ printf 'a\\nb\\nc\\n' \u003e A; printf 'a\\nX\\nc\\n' \u003e B\n$ diffutils diff $'\\xff--width=5' A B\nthread 'main' panicked at src/params.rs:116:45:\ncalled `Result::unwrap()` on an `Err` value: \"\\xFF--width=5\"\n$ echo $?\n134\n```\n\n`diff` aborts (panic, exit 134) when given a non-UTF-8 argument whose lossy form ends in `--width=\u003cdigits\u003e` — e.g. an argument with a leading invalid byte like `$'\\xff--width=5'`.\n\n## Expected behavior\n\nMatch GNU: the unrecognized argument is a file operand; with three operands diff reports the extra operand and exits 2.\n\n```console\n$ /usr/bin/diff $'\\xff--width=5' A B\ndiff: extra operand 'B'\n$ echo $?\n2\n```\n\n## Root cause\n\nThe `--width` regex lacks a start anchor, unlike the sibling `--tabsize` one:\n\n```rust\n// src/params.rs:62-63\nlet tabsize_re = Regex::new(r\"^--tabsize=(?\u003cnum\u003e\\d+)$\").unwrap(); // anchored — safe\nlet width_re = Regex::new(r\"--width=(?P\u003clong\u003e\\d+)$\").unwrap(); // no leading ^\n\n// src/params.rs:115-116\nif width_re.is_match(param.to_string_lossy().as_ref()) { // matches lossy form\n let param = param.into_string().unwrap(); // line 116: Err on non-UTF-8\n```\n\n`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.\nFix: 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.)\n\n_Found by our static analysis tooling._","author":{"url":"https://github.com/leeewee","@type":"Person","name":"leeewee"},"datePublished":"2026-06-16T08:39:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/247/diffutils/issues/247"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5815e52e-0a0a-cdf5-c444-223c74c509ca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7A8:3E0D60:3485013:4814BAA:6A4F25C0 |
| html-safe-nonce | 5ce63792c7c7fc9d7bf078e11ba08589066102199f07756c7e1acedee14a0513 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0E4OjNFMEQ2MDozNDg1MDEzOjQ4MTRCQUE6NkE0RjI1QzAiLCJ2aXNpdG9yX2lkIjoiMzUzMDEyMDkzMDQ2MTE2NDk5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ce6c447959ffbc80583601d4569ed2d4baa5ebcd180f1f05509c7b15453469b4 |
| hovercard-subject-tag | issue:4672525756 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/uutils/diffutils/247/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f92bdcadc39f3b77196528c4aada698feaf477f202b0b38ee271007ac60afd81/uutils/diffutils/issues/247 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f92bdcadc39f3b77196528c4aada698feaf477f202b0b38ee271007ac60afd81/uutils/diffutils/issues/247 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | leeewee |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/uutils/diffutils git https://github.com/uutils/diffutils.git |
| octolytics-dimension-user_id | 5148717 |
| octolytics-dimension-user_login | uutils |
| octolytics-dimension-repository_id | 341787720 |
| octolytics-dimension-repository_nwo | uutils/diffutils |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 341787720 |
| octolytics-dimension-repository_network_root_nwo | uutils/diffutils |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width