Repository navigation
sort: fix panic on non-UTF-8 filenames with --files0-from ( Fixes #9696 ) - #11592
Closed
ppmpreetham wants to merge 2 commits into
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
ppmpreetham wants to merge 2 commits into
Conversation
Contributor
|
Would you fix |
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 #9696
Description
When parsing NUL-separated filenames via
--files0-from,sortpreviously enforced strict UTF-8 validation usingstd::str::from_utf8().expect(...). This caused an immediate panic when encountering valid non-UTF-8 paths. GNUsorttreats filenames as raw bytes and does not require them to be UTF-8 encoded.This PR aligns
uutilswith GNU behavior by removing the strict UTF-8 enforcement:OsStr::from_bytesto losslessly cast the raw bytes directly into anOsString, preserving arbitrary byte sequences exactly as GNU does.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):