Repository navigation
fix(builtins): byte-exact tee, split, cut and xxd -r; sort -o refuses non-UTF-8 in place - #2945
Merged
Merged
Conversation
A differential probe on a Latin-1 + invalid-byte file found byte tools decoding through text: tee rewrote output and file to U+FFFD, split wrote damaged pieces (and -l dropped \r), cut -b was an alias of -c, xxd -r returned lossy UTF-8. All now work on bytes. sort -o FILE FILE refuses a non-UTF-8 FILE instead of destroying it, like sed -i. Refs #2935
Review summary — fix(builtins): byte-exact tee, split, cut and xxd -r; sort -o refuses non-UTF-8 in placeVerdict (3rd push, Findings:
This push: Could not review: per project rules no build/test run (test expectations read against the implementation instead); check-then-act TOCTOU between canonicalize and write noted but not filed — same race exists in GNU sort's stat/open and the VFS is session-local. |
./f, d/../f and /cwd/f aliases of the input bypassed the refusal.
ln -s f link; sort -o link f bypassed the lexical comparison.
2 tasks done
chaliy
added a commit
that referenced
this pull request
Nov 19, 2026
… unix (#2955) Two CI-green fixes. Nine heapless 0.7.17 unsoundness advisories (RUSTSEC-2026-0574 through 0582) were published on 2026-11-18. Cargo scans run `--deny unsound` over every discovered lockfile, so `scripts/audit-lockfiles.sh` failed on both the workspace lock and `crates/bashkit/fuzz/Cargo.lock`. The advisory database is fetched at job time, so this went red with nothing in the tree changed. postcard 1.1.3 is its newest release and requires `heapless ^0.7`, so no bump reaches the patched 0.9.4. But heapless is an optional postcard dependency and postcard's `default = ["heapless-cas"]` exists only to enable it; both of our manifests asked for `features = ["alloc"]` while leaving default features on, pulling heapless in by accident. Only `to_allocvec`, `from_bytes` and `to_slice` are used here, all of which need `alloc` alone. Declaring postcard with `default-features = false` drops heapless and its chain (atomic-polyfill, critical-section, hash32, spin, lock_api, rustc_version) from both lockfiles, so the unsound code leaves the build instead of having its advisories suppressed. That also satisfies the recorded removal condition for RUSTSEC-2023-0089 (atomic-polyfill), now absent from every discovered lockfile, so the suppression is retired from deny.toml and the threat model. `bashkit-monty` is a fork held at upstream Monty 1.5.0 outside `bashkit fork:` markers, so the postcard divergence is marked with its reason and a removal condition. knowledge/operations/dependencies.md described a marker as covering a dependency's version; the check compares the whole dependency spec, so a feature or default-features divergence is markable too, and postcard is the first of that kind. Separately, `byte_tools_match_real_bash_on_non_utf8_input` landed in #2945 without the platform gate every other host-bash oracle in the file carries, and the Windows nightly went red on its first run afterwards. On windows-latest `bash` is the WSL launcher, so the failure was in the test's own `assert!(expected.status.success())` precondition, before any Bashkit output was compared. Gated off unix as knowledge/operations/testing.md requires. Windows keeps byte-exactness coverage through the non-oracle tests in the same file. Verified: audit-lockfiles.sh exits 0 with no denied warnings across all six cargo lockfiles, `cargo deny check licenses sources` reports licenses and sources ok, `cargo vet --locked` succeeds, and a workflow_dispatch of the Windows nightly on the branch passes with the oracle reported ignored.
2 tasks done
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.
Requested by Михайло · project thread
Follow-up to #2935. A differential probe ran 60 commands through bashkit and real bash on a file containing Latin-1 and invalid bytes. It found 5 more byte-oriented builtins that decode their input as text and replace invalid bytes with
�.What changed
teenow passes stdin through as bytes, both to stdout and to its files. Before, both were rewritten to U+FFFD.split(-b,-l,-n) works on bytes, so the pieces concatenate back to the exact input.-lalso keeps\ron CRLF lines; it used to drop it.cut -bnow selects bytes. Before, it was an alias of-c.cut -candcut -fkeep invalid bytes as they are:-ccounts each invalid byte as one character.xxd -routputs raw bytes. Before, it returned lossy UTF-8.sort -o FILE FILEused to silently destroy a non-UTF-8 FILE by rewriting it through a lossy decode. It now refuses with exit 2, the same waysed -idoes (L-SED-003). Sorting into a different file is unchanged.Text tools (
sort,sed,awk, ...) still decode their input with replacement by design (L-STREAM-001). That row now lists which builtins are byte-exact.Before / After
On
printf 'K\366ln,\377\376\000z\nb,K\303\266ln\200\r\n' > in.bin:A new test,
byte_tools_match_real_bash_on_non_utf8_input, compares stdout byte for byte with real bash fortee,split -b/-l,cut -b/--complement/-c/-f.Risk
cut -bon multibyte UTF-8 now cuts bytes, as GNU does, so it can split a character.cut -cstill counts characters.sort -o f fon a non-UTF-8 file now gets exit 2 instead of a silently damaged file.Checklist
cut,split,tee,sortandxxdpass, 242 of them.