Skip to content

find: don't panic on invalid-UTF-8 arguments - #817

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-printf-invalid-utf8-panic
Open

find: don't panic on invalid-UTF-8 arguments#817
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-printf-invalid-utf8-panic

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 7, 2026

Copy link
Copy Markdown

Summary

find used std::env::args(), which panics if any argument is not
valid UTF-8:

$ find d -printf $'%\xff|\n'
thread 'main' panicked at ...: called `Result::unwrap()` on an `Err` value
$ echo $?
101

The panic happens during argument collection, before the -printf
format parser is ever reached.

This switches to std::env::args_os() and reports invalid UTF-8 as a
normal error (exit 1) instead of panicking:

$ find d -printf $'%\xff|\n'
find: invalid UTF-8 was found in one of the arguments: %�|
$ echo $?
1

Full binary/byte passthrough (matching GNU find's behavior of
accepting arbitrary bytes) would need find_main and the whole
argument-parsing pipeline to switch from &str to OsStr, which is
a much larger refactor — happy to look into that separately if
maintainers want it, but this fixes the immediate panic/exit-101 bug
with a minimal change.

Test plan

  • Added find_printf_invalid_utf8_format_does_not_panic integration test
  • cargo test — 226 + 60 + ... all passing (full suite green)
  • cargo fmt --check clean
  • Manually reproduced the original panic and confirmed the fix

Fixes #816

std::env::args() panics if any argument is not valid UTF-8, so a
non-UTF-8 -printf format string (or any other argument) crashed find
with exit code 101 instead of a normal error.

Collect args via env::args_os() instead and report invalid UTF-8 as
a regular error (exit 1) rather than panicking.

Fixes uutils#816
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.93%. Comparing base (1f19cdd) to head (5fe6fe6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #817   +/-   ##
=======================================
  Coverage   91.93%   91.93%           
=======================================
  Files          35       35           
  Lines        7251     7258    +7     
  Branches      378      378           
=======================================
+ Hits         6666     6673    +7     
  Misses        443      443           
  Partials      142      142           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Commit 5fe6fe6 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 314 / PASSED: 267 / FAILED: 41 / SKIPPED: 6
  Reference: TOTAL: 312 / PASSED: 266 / FAILED: 40 / SKIPPED: 6

Changes from main branch:
  TOTAL: +2
  PASSED: +1
  FAILED: +1

New test failures (1):
  - gnu/okdir_path_empty

@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing MsfPablo:fix-printf-invalid-utf8-panic (5fe6fe6) with main (1f19cdd)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-printf panics on an invalid-UTF-8 format string (exit 101)

1 participant