Skip to content

find: avoid panic on a non-UTF-8 argument - #833

Merged
sylvestre merged 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-find-non-utf8-args
Aug 18, 2026
Merged

find: avoid panic on a non-UTF-8 argument#833
sylvestre merged 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-find-non-utf8-args

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown
Contributor

Summary

A non-UTF-8 argument makes find panic during argument collection, before the format
parser is ever reached:

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

Root cause

main collected arguments with std::env::args(), which panics on a non-UTF-8 argument.

Fix

Collect with std::env::args_os() and report the first non-UTF-8 argument as an error,
exiting with code 1 instead of aborting. The conversion is extracted into a small
collect_utf8_args helper so it can be unit-tested. Full GNU-style byte pass-through of
the format string is a larger change and left as a follow-up.

Verification

$ find d -printf $'%\xff|\n'
find: invalid (non-UTF-8) argument: %<0xff>|
$ echo $?
1

Adds unit tests collects_valid_utf8_args and non_utf8_arg_is_rejected_not_panicking.
cargo fmt and cargo clippy --bin find are clean.

Fixes #816.

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.17%. Comparing base (2a3eac9) to head (5103940).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #833      +/-   ##
==========================================
+ Coverage   92.15%   92.17%   +0.01%     
==========================================
  Files          35       35              
  Lines        7377     7395      +18     
  Branches      383      383              
==========================================
+ Hits         6798     6816      +18     
  Misses        438      438              
  Partials      141      141              

☔ 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.

@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing AlejandroCoronadoN:fix-find-non-utf8-args (5103940) with main (2a3eac9)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown

Commit 2e69802 has test result changes:

bfs testsuite:

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

Changes from main branch:
  TOTAL: -1
  PASSED: -1
  FAILED: +0

@sylvestre

Copy link
Copy Markdown
Contributor

please add a test_find.rs

@AlejandroCoronadoN

Copy link
Copy Markdown
Contributor Author

Done, added an integration test in test_find.rs that passes a non-UTF-8 argument and checks it errors cleanly instead of panicking.

@github-actions

Copy link
Copy Markdown

Commit 977aa58 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 315 / PASSED: 267 / FAILED: 42 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

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

New test failures (1):
  - gnu/okdir_path_dot

Test improvements (1):
  + gnu/files0_from_ok

std::env::args panics on a non-UTF-8 argument. Read the arguments with args_os
and report the first invalid one with a clean error and exit 1, instead of
aborting (uutils#816). Adds a helper unit test and a test_find.rs test.
@sylvestre
sylvestre force-pushed the fix-find-non-utf8-args branch from 977aa58 to 5103940 Compare August 18, 2026 17:22
@sylvestre
sylvestre merged commit e1927ac into uutils:main Aug 18, 2026
23 checks passed
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)

2 participants