Repository navigation
sort: fix panic on non-UTF-8 filenames with --files0-from - #11593
Conversation
for more information, see https://pre-commit.ci
This reverts commit 446fc9d.
|
Can you please add a test to |
|
GNU testsuite comparison: |
|
added a test for the same |
Merging this PR will degrade performance by 4.67%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
please fix clippy |
|
GNU testsuite comparison: |
| let (at, mut ucmd) = at_and_ucmd!(); | ||
|
|
||
| // non-UTF-8 bytes (0xFF) | ||
| let filename = std::ffi::OsString::from_vec(vec![b'a', 0xFF, b'b']); |
There was a problem hiding this comment.
| let filename = std::ffi::OsString::from_vec(vec![b'a', 0xFF, b'b']); | |
| let filename = std::ffi::OsString::from_vec(b"a\xffb".into()); |
Something like this would be more readable
There was a problem hiding this comment.
yes, but cspell stops me
There was a problem hiding this comment.
just add it to the ignore list
| #[cfg(not(unix))] | ||
| let f_str = String::from_utf8_lossy(&line); | ||
| #[cfg(not(unix))] | ||
| let f = OsStr::new(f_str.as_ref()); |
There was a problem hiding this comment.
| #[cfg(not(unix))] | |
| let f_str = String::from_utf8_lossy(&line); | |
| #[cfg(not(unix))] | |
| let f = OsStr::new(f_str.as_ref()); | |
| #[cfg(not(unix))] | |
| let f = { | |
| let f_str = String::from_utf8_lossy(&line); | |
| OsStr::new(f_str.as_ref()) | |
| }; |
Avoid writing #[cfg(not(unix))] more than once
| if f == STDIN_FILE { | ||
| return Err(SortError::MinusInStdIn.into()); | ||
| } | ||
| if f.is_empty() { | ||
| return Err(SortError::ZeroLengthFileName { | ||
| file: files0_from, | ||
| line_num: line_num + 1, | ||
| } | ||
| _ => {} | ||
| .into()); |
There was a problem hiding this comment.
Not sure why you can't keep the match here
|
some jobs are failing btw :) |
|
GNU testsuite comparison: |
|
still fails |
|
GNU testsuite comparison: |
|
I'll look into this |
| Self::Byte(*value) | ||
| } | ||
| } | ||
| impl_from_for_enum!(CharByte: |
There was a problem hiding this comment.
this is from the other pr
| checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" | ||
| dependencies = [ | ||
| "windows-sys 0.60.2", | ||
| "windows-sys 0.61.2", |
There was a problem hiding this comment.
i think it is unrelated to this pr
|
|
||
| // words to ignore (even if they are in the flagWords) | ||
| "ignoreWords": [], | ||
| "ignoreWords": ["xffb"], |
There was a problem hiding this comment.
please add it in .vscode/cspell.dictionaries/jargon.wordlist.txt instead
|
It should work on all OSes now. |
|
please remove your changes in cargo.lock |
|
done :) |
|
GNU testsuite comparison: |
| .args(args) | ||
| .ignore_stdin_write_error() | ||
| .pipe_in("a''b\n") | ||
| .ignore_stdin_write_error() |
There was a problem hiding this comment.
this was failing the tests..
in this test, cut -d "''" -f2 is invalid at argument parsing time. So cut can exit immediately, before reading a''b\n from stdin. The test writes .pipe_in(...) on a background thread...
if cut already exited, that write gets Broken pipe, and the test panics before the real assertion runs.
There was a problem hiding this comment.
sorry but you touched sort ?! so, why it is impacting cut
There was a problem hiding this comment.
sort did not break cut. CI just reported another failing test in the same full run.
There was a problem hiding this comment.
ok, remove it please
one pr = one change
There was a problem hiding this comment.
okay, will remove it
|
|
||
| #[test] | ||
| // Test for GNU tests/sort/sort-files0-from.pl "non-utf8" | ||
| #[cfg(unix)] |
There was a problem hiding this comment.
seems unnecessary because of the next line
|
thanks |
Re-opening this to fix the hidden character warning in the previous branch name. Supersedes #11592.
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):