Repository navigation
test(executor): pin fd 0 consumption cursor to transport units - #711
Merged
Merged
Conversation
The shared fd 0 cursor (FUNCTION_STDIN_OFFSET) is a byte index into the shell's transport text: read_function_stdin, function_stdin_remaining and select all slice the same buffer with it. The pipeline drivers therefore advance it by the transport length they handed the external child (pipeline_stages.rs `input.len()`, pipeline_exec.rs `stage0_input.len()`), never by shell_text_to_raw_bytes(..).len(): a raw delta under-advances by the carrier overhead and replays bytes the child already consumed. This is the unit-twin of #695 / unixwin/niubash#383. There a byte count handed to the user had to be raw; here an index into transport text must be transport, so the three audited sites are correct as written. Document the invariant and add regression tests that fail if a future sweep converts them to raw units.
This was referenced Oct 17, 2026
This was referenced Oct 30, 2026
Closed
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.
What this is
Follow-up to #695 (fixing unixwin/niubash#383, the inline
wc -ctransport-bytemiscount). That PR's body flagged the fd 0 consumption cursor as an
"unresolved, deliberately not fixed" candidate of the same class:
pipeline_stages.rsself.pipeline_stdin_consumed.set(Some(input.len()))(payload written via
shell_text_to_raw_bytes(input))pipeline_exec.rs(base + stage0_input.len())forFUNCTION_STDIN_OFFSET(payload written via
shell_text_to_raw_bytes(&stage0_input))I audited those sites. They are correct as written — the cursor is not a raw
byte count, it is a byte index into the shell's transport text, and the two
are deliberately different units. This PR records the invariant and pins it
with regression tests so a future sweep does not "fix" the three sites into a
bug.
Why the sites are right (construction proof)
Between in-process stages a payload travels as transport text: a raw control
byte is the carrier pair
U+E000 + U+E0xx(locale.rs:352), and a lone invalidhigh byte takes the same shape. So
transport_len != raw_len— x6 per controlbyte, x2 per high byte — and
shell_text_to_raw_bytes(..).len()recovers theraw length.
FUNCTION_STDIN_OFFSETis a byte index into that transport buffer. Everyconsumer slices with it and therefore requires transport units:
read_io.rs::read_function_stdin—&input[offset..]thenoffset + consumed(both transport);shell_options.rs::function_stdin_remaining—input[offset..];select_exec.rs::read_select_input—&stdin_content[*stdin_offset..];function_calls.rs—input.get(offset..)andparent_stdin_base + child_offset.The pipeline delta is folded as
base + consumed, wherebaseis itself atransport offset, so
consumedmust be transport too.input/stage0_inputis exactly
FUNCTION_STDIN[base..], sobase + transport_lenlands onend-of-buffer (a valid transport index) whereas a raw delta stops short by the
carrier overhead and re-exposes already-consumed bytes.
#695 was the reverse case: a count reported to the user (
wc -c) had to beraw. Here an index into transport text must be transport. Same boundary,
opposite direction.
Evidence
Debug probe at the real call site,
printf '\033A\n' | { od -An -tx1 | od -An -tx1; }(concurrent external path,
pipeline_exec.rs):I then applied the naive raw-unit change at the three sites and the follow-up
reader visibly replayed consumed bytes instead of seeing EOF:
{ od | od; read x; ... } <<< $'\033A'after=[] rc=1after=[\u{e01c}A] rc=0{ od | od; read x; ... } <<< $'ab\315X'after=[] rc=1after=[\u{e0ce}X] rc=0{ read x; od | od; read y; } <<< $'line\n\033B\nTAIL'y=[] rc=1y=[TAIL] rc=0The raw form leaks half of a carrier pair (
U+E01C/U+E0CE) plus the tail.So the change that looked like the fix would have been the bug.
Changes
(no behavior change).
tests/fd0_consumption_cursor_transport_units.rs: four tests that fullyconsume a carrier-bearing shared fd 0 with an external pipeline and assert
the follow-up reader sees EOF, plus a remainder-path round trip. Three of
them fail under a raw-unit cursor.
Tests run
issue647_function_redirect_stdin_regressions::function_call_file_redirect_survives_external_spawnfails, but it is pre-existing and environmental: its
external_true()helperinjects an unquoted
C:\...\true.exeinto the script, which the shell manglesto
C:Userscmx...: command not found. Unrelated to this (comment-only) change.Same class, not this PR
While auditing I found a genuine, user-visible instance of the class in the
readbuiltin's-n/-Nchar limit (read_io.rs): the limit counts transportchars, so a carrier pair is split and counted as two characters —
That is a separate fix (paired-char consumption in
read_function_stdin) and isleft out here to keep this change scoped to the audited cursor sites.