Repository navigation
od: preserve non-UTF-8 file operands - #15242
ozenyunus35 wants to merge 3 commits into
Conversation
od collected its arguments with `collect_ignore()`, which silently drops every argument that is not valid UTF-8. Such a file operand was lost, so `od $'\xff'` read standard input (and hung on a terminal) instead of dumping the file or reporting that it does not exist. Pass the raw arguments to clap and keep file operands as `OsString` all the way to `File::open`. Offsets and labels are still parsed from operands that are valid UTF-8. Fixes uutils#12794
|
|
||
| let (at, mut ucmd) = at_and_ucmd!(); | ||
| let name = OsStr::from_bytes(b"\xff"); | ||
| std::fs::write(at.plus(name), "abcdefghijklmnopqrstuvwxyz\n").unwrap(); |
There was a problem hiding this comment.
Better to user at.write(file, content) here.
There was a problem hiding this comment.
Unless I'm missing something that doesn't work because name is an OsStr whereas at.write expects a &str.
|
The tests you added are broken in web-assembly, hence the CI fails. I suggest setting the tests' cfgs to #[cfg(not(any(target_os = "wasi", windows)))] |
wasmtime cannot pass an argument that is not valid UTF-8 to the utility, so these tests cannot run there. Mark them like the other tests that depend on non-UTF-8 arguments.
|
Thanks for the review! I updated the tests in 36237d8. I used the repository's existing Regarding |
| show_error!( | ||
| "{}: {}", | ||
| self.file_name.unwrap_or("I/O"), | ||
| self.file_name.map_or("I/O".into(), OsStr::to_string_lossy), |
There was a problem hiding this comment.
could use maybe_quote() here like the open error above, no?
| .pipe_in("not read") | ||
| .succeeds() | ||
| .stdout_only(unindent(ALPHA_OUT)); | ||
| } |
There was a problem hiding this comment.
could you please also add a test with an offset, e.g. od --traditional <non-utf8> 10?
|
@sylvestre done in 4482a3a: the read error now uses |
Summary
Fixes #12794.
odcurrently drops command-line arguments that are not valid UTF-8. When such an argument is a filename,odbehaves as if no file was provided and falls back to reading standard input.This can cause
odto wait for input unexpectedly or read unrelated data instead of reporting a missing file.Changes
OsStringthroughout argument parsing and file handling.File::open.Testing
Added two regression tests:
The first test fails before the fix and passes afterward.
Validation performed on macOS:
test_od: 75 passed.uu_odunit tests: 55 passed.cargo fmt --check: passed.-D warnings: passed.The Linux-specific filesystem test could not be executed on macOS and will be exercised by Linux CI.
Compatibility
The change is limited to
odargument and file handling. Existing behavior for valid UTF-8 filenames, standard input, and offsets is preserved.AI Assistance
Claude Code was used to assist with implementation and testing.