find: don't panic on invalid-UTF-8 arguments - #817
Open
MsfPablo wants to merge 1 commit into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Commit 5fe6fe6 has test result changes: bfs testsuite: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
findusedstd::env::args(), which panics if any argument is notvalid UTF-8:
The panic happens during argument collection, before the
-printfformat parser is ever reached.
This switches to
std::env::args_os()and reports invalid UTF-8 as anormal error (exit 1) instead of panicking:
Full binary/byte passthrough (matching GNU find's behavior of
accepting arbitrary bytes) would need
find_mainand the wholeargument-parsing pipeline to switch from
&strtoOsStr, which isa 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
find_printf_invalid_utf8_format_does_not_panicintegration testcargo test— 226 + 60 + ... all passing (full suite green)cargo fmt --checkcleanFixes #816