Skip to content

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

Open
AlejandroCoronadoN wants to merge 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-find-non-utf8-args
Open

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

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown

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.

main collected args with std::env::args(), which panics on a non-UTF-8
argument (e.g. ). Collect with args_os and report the
first invalid argument as an error, exiting 1 instead of aborting. Adds unit
tests for the extracted helper.

Fixes uutils#816.
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.89%. Comparing base (5aa8184) to head (2e69802).

Files with missing lines Patch % Lines
src/find/main.rs 78.94% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #833      +/-   ##
==========================================
- Coverage   91.93%   91.89%   -0.04%     
==========================================
  Files          35       35              
  Lines        7253     7271      +18     
  Branches      378      378              
==========================================
+ Hits         6668     6682      +14     
- Misses        443      447       +4     
  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.

@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 (2e69802) with main (5aa8184)

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

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