sort: do not panic on a non-UTF-8 --files0-from name#12773
Open
leeewee wants to merge 1 commit into
Open
Conversation
`sort --files0-from=F` decoded each NUL-separated filename with `str::from_utf8(&line).expect(...)`, aborting on any non-UTF-8 byte — Linux filenames are arbitrary byte strings. Carry the name as an `OsString` built from the raw bytes (via `uucore::os_string_from_vec`) and do the "-"/empty checks on the bytes, so a non-UTF-8 name flows into the normal open-failure path (exit 2) like GNU instead of aborting.
|
GNU testsuite comparison: |
Merging this PR will improve performance by 4.3%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ls_recursive_balanced_tree[(6, 4, 15)] |
52.3 ms | 49.6 ms | +5.53% |
| ⚡ | Simulation | ls_recursive_wide_tree[(10000, 1000)] |
34.3 ms | 33 ms | +3.95% |
| ⚡ | Simulation | single_date_now |
85.5 µs | 82.7 µs | +3.41% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing leeewee:sort-fix-files0-from-non-utf8 (2e84ad1) with main (220a8ec)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
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.
Fixes #12772
sort --files0-from=Fdecoded each NUL-separated filename withstr::from_utf8(&line).expect(...), which panicked (exit 134) on any non-UTF-8 byte.Build the name as an
OsStringfrom the raw bytes viauucore::os_string_from_vecand run the-/empty-name checks on the bytes, so a non-UTF-8 name now fails to open gracefully (exit 2) like GNU instead of aborting. Other cases (-, empty, valid list) are unchanged.Added a Unix-gated regression test.