Skip to content

sort: use os_string_from_vec for --files0-from names - #12773

Merged
RenjiSann merged 1 commit into
uutils:mainfrom
leeewee:sort-fix-files0-from-non-utf8
Jul 21, 2026
Merged

RenjiSann merged 1 commit into
uutils:mainfrom
leeewee:sort-fix-files0-from-non-utf8

Conversation

@leeewee

@leeewee leeewee commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #11593.

#11593 fixed the --files0-from non-UTF-8 panic by decoding the raw bytes inline (#[cfg(unix)] OsStr::from_bytes / #[cfg(not(unix))] from_utf8_lossy). This replaces that inline reimplementation with the shared uucore::os_string_from_vec helper, so the byte→OsString conversion has a single source of truth rather than duplicated (and already slightly diverging) logic. The -/empty-name checks now run on the raw bytes.

Behavior is unchanged on Unix (both are lossless); the Unix-gated regression test (a non-UTF-8 name → cannot read, exit 2) still passes.

@github-actions

github-actions Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)

@codspeed

codspeed Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 339 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing leeewee:sort-fix-files0-from-non-utf8 (42e69fd) with main (ef50d8b)

Open in CodSpeed

Footnotes

  1. 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. ↩

@RenjiSann RenjiSann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the merge conflicts, otherwise, good job :D

@leeewee

leeewee commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Please fix the merge conflicts, otherwise, good job :D

The same panic was fixed by #11593 (merged 2026-06-30, Fixes #9696), which landed the equivalent OsStr::from_bytes handling plus a test_files0_from_non_utf8 test on main. That's also the source of the merge conflict here. Thanks for the review @RenjiSann; this one's redundant now and I am going to close this.

@RenjiSann

Copy link
Copy Markdown
Collaborator

I like this one better because it uses uucore::os_string_from_vec. Reimplementing its behavior in the code like #11593 did adds burden to the tech debt because we'd need to make sure these are in sync (which it curently isn't btw).

`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.
@leeewee
leeewee force-pushed the sort-fix-files0-from-non-utf8 branch from 2e84ad1 to 42e69fd Compare July 21, 2026 05:33
@leeewee leeewee changed the title sort: do not panic on a non-UTF-8 --files0-from name sort: use os_string_from_vec for --files0-from names Jul 21, 2026
@leeewee

leeewee commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @RenjiSann! I've rebased onto main and resolved the conflicts.

@RenjiSann
RenjiSann merged commit 6e28633 into uutils:main Jul 21, 2026
197 of 234 checks passed
@RenjiSann

Copy link
Copy Markdown
Collaborator

Thanks !

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.

2 participants