Skip to content

sort: fix panic on non-UTF-8 filenames with --files0-from ( Fixes #9696 ) - #11592

Closed
ppmpreetham wants to merge 2 commits into
uutils:mainfrom
ppmpreetham:fix/9692-Panics-on-Non‑UTF‑8

Hidden character warning

The head ref may contain hidden characters: "fix/9692-Panics-on-Non\u2011UTF\u20118"
Closed

ppmpreetham wants to merge 2 commits into
uutils:mainfrom
ppmpreetham:fix/9692-Panics-on-Non‑UTF‑8

Conversation

@ppmpreetham

Copy link
Copy Markdown
Contributor

Fixes #9696

Description

When parsing NUL-separated filenames via --files0-from, sort previously enforced strict UTF-8 validation using std::str::from_utf8().expect(...). This caused an immediate panic when encountering valid non-UTF-8 paths. GNU sort treats filenames as raw bytes and does not require them to be UTF-8 encoded.

This PR aligns uutils with GNU behavior by removing the strict UTF-8 enforcement:

  • On Unix: We now use OsStr::from_bytes to losslessly cast the raw bytes directly into an OsString, preserving arbitrary byte sequences exactly as GNU does.
  • On non-Unix (e.g., Windows): We safely fall back to String::from_utf8_lossy. This prevents the program from panicking or failing on invalid UTF-8 sequences, ensuring graceful error handling across all platforms.

Testing

Reproduced the issue and verified the fix locally (both linux and windows):

$ printf "20\n10\n" > "weird$(printf '\xff')name"
$ printf "weird$(printf '\xff')name\0" > list0
$ ./target/release/coreutils sort --files0-from=list0
10
20

@oech3

oech3 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Would you fix Hidden character warning The head ref may contain hidden characters: "fix/9692-Panics-on-Non\u2011UTF\u20118"?

@ppmpreetham ppmpreetham closed this Apr 2, 2026
@ppmpreetham
ppmpreetham deleted the fix/9692-Panics-on-Non‑UTF‑8 branch April 2, 2026 07:14
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.

sort --files0-from Requires UTF-8 / Panics on Non‑UTF‑8 Filenames

2 participants