Skip to content

fix(executor): restore DATA_SQUOTE carrier on pipeline child-argv boundaries - #3511

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
Catapult291:fix-d11-only
Nov 14, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
Catapult291:fix-d11-only

Conversation

@Catapult291

Copy link
Copy Markdown
Contributor

Summary

A pipeline member's argument word that mixes a live backtick command substitution with an apostrophe reached the external child's argv with the DATA_SQUOTE carrier (0x17, U+0017) still encoded — the child received a raw control byte instead of the apostrophe:

$ rubash -c 'python -c "import sys; print(ascii(sys.argv[1]))" "A `echo AAA` B member'"'"'s C" | tail -1'
'A AAA B member\x17s C'          # rubash (before)
"A AAA B member's C"             # GNU bash 5.3.20

Root cause: the lexer encodes every ' inside a double-quoted word that also carries a live backtick substitution as DATA_SQUOTE (src/lexer/quotes.rs:208). The plain-command argv boundary decodes it through materialize_expanded_command_word (command_prepare.rs), but the pipeline spawn faces — the sequential external stage (pipeline_stages.rs) and the concurrent fast path (pipeline_exec.rs, concurrent_external_stage_spec / execute_external_pipeline_concurrently) — only ran restore_command_substitution_output, whose replace chain covers DATA_BACKTICK / DATA_DOLLAR / PROTECTED_BACKSLASH / DATA_BACKSLASH / DATA_DQUOTE and never DATA_SQUOTE.

Changes

  • Add the DATA_SQUOTE → ' restore to restore_command_substitution_output (execution_misc.rs). The remaining callers that reach a child-argv boundary need the same decode; the in-flight transport callers pass through it and the carrier byte stays decodable at each argv materialization point.
  • Raw-byte safe: typed 0x17 user data cannot arrive bare (it rides the raw-byte marker pair on entry), matching the plain-command boundary's existing .replace decode — same argument the family already relies on for DATA_BACKTICK/DATA_DQUOTE.
  • GNU reference: subst.c:11882-11886 (case '\'') copies a single-quoted span verbatim — the child argv gets a real apostrophe.
  • Regression tests: tests/d11_pipeline_squote_carrier_regressions.rs (6 cells). All 6 failed on the unfixed tree with \x17 in the child argv; all pass after the fix. Cells cover the full trigger shape, the concurrent fast-path face (| cat), multiple apostrophes, and the non-triggering neighbors ($(), no-pipeline, apostrophe-only) as guards against over-decoding.

Trigger elements (diagnosis notes)

  1. An apostrophe inside the double-quoted word (apostrophe alone is fine);
  2. a live backtick substitution in the same word ($() did not leak through the plain walker's restore);
  3. the command runs as a pipeline member (any external tail: | tail, | cat, …).

Test plan

  • cargo test --test d11_pipeline_squote_carrier_regressions — 6/6 (0/6 before the fix).
  • cargo test --lib — 1349 passed / 1 pre-existing failure (api::consumer_tests::issue2084, fails on master too).
  • Targeted carrier/pipeline suites: marker_leak_golden, marker_registry_roundtrips, issue124_eval_quote_marker, issue1540_pipeline_element_expansion_regressions, issue3058_assignment_comsub_carrier_leak, issue3103_command_word_split_carrier, issue354_carrier_comsub_regressions, issue548_arith_for_carrier_echo_regressions, issue948_pua_carrier_passthrough_regressions, issue2129_startup_carrier_recursion, issue2137_execution_scope_markers, issue2883_read_prompt_carrier_regressions, issue735_pua_marker_collision, pipeline_streaming_regressions — all green.
  • Two pre-existing failures unrelated to this change, verified identical on unfixed master: carrier_byte_class_regressions (2 PUA cells), issue3308_comsub_pipeline_stderr_redirects (9 script-mode cells).
  • Installed-shell verification (Windows, niubash 1.5.0 hosting this engine): the matrix above plus regression sweeps (yes | head -3 2>/dev/null, 2>&1, seq 1 100000 | cat | wc -l data integrity) all clean.

Related local defect record: niubash defects list D11 (2026-11-14).

…ndaries

A pipeline member's argument word that mixes a live backtick command
substitution with an apostrophe reached the external child's argv with
the DATA_SQUOTE carrier (0x17) still encoded: "A `echo AAA` B member's C"
| tail -1 handed python argv[1] = 'A AAA B member\x17s C' instead of
"A AAA B member's C". The plain-command argv boundary decodes the
carrier through materialize_expanded_command_word (command_prepare.rs),
but the pipeline spawn faces — the sequential external stage
(pipeline_stages.rs) and the concurrent fast path
(pipeline_exec.rs concurrent_external_stage_spec / execute_external_
pipeline_concurrently) — only ran restore_command_substitution_output,
whose replace chain covers DATA_BACKTICK / DATA_DOLLAR /
PROTECTED_BACKSLASH / DATA_BACKSLASH / DATA_DQUOTE and never
DATA_SQUOTE.

Add the DATA_SQUOTE restore to restore_command_substitution_output
itself: every remaining caller that reaches a child-argv boundary needs
the same decode, and the internal transport callers (expand_word.rs,
command_substitution_values.rs, substitution_metadata.rs) pass through
it in flight, where a later boundary (materialize_expanded_command_word
or the same restore at argv) still sees the carrier byte it must
decode — no double-decode hazard, because every argv materialization
point runs the family exactly once. Raw-byte safe: typed 0x17 user data
cannot arrive bare (markers.rs raw-byte marker pair on entry), matching
the plain-command boundary's .replace decode.

GNU: subst.c:11882-11886 (case '\'') copies a single-quoted span
verbatim — the child argv gets a real apostrophe.

Regressions: tests/d11_pipeline_squote_carrier_regressions.rs (6 cells;
all failed on the unfixed tree with \x17 in the child argv).
@caomengxuan666 caomengxuan666 added the bug Something isn't working label Nov 13, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 13, 2026
@caomengxuan666 caomengxuan666 added P2-medium 中:次要缺陷或边缘路径,排期修复 area:carrier in-band carrier/marker protocol: markers.rs, decode boundaries, PUA/C0 family:M1 taxonomy M1: producer/carrier encoded, consumer forgot to decode labels Nov 13, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the follow-up, @Catapult291 — received and recorded.

What I captured: a pipeline member's argument word mixing a live backtick substitution with an apostrophe reached the external child's argv with the DATA_SQUOTE carrier (0x17) still encoded — member\x17s instead of member's. The fix adds the DATA_SQUOTE → ' restore to the shared restore_command_substitution_output (execution_misc.rs), with 6 new regression cells in tests/d11_pipeline_squote_carrier_regressions.rs covering both pipeline spawn faces, multiple apostrophes, and the non-triggering neighbours. GNU reference (subst.c:11882-11886) and the fail-first claim (0/6 before, 6/6 after) are noted.

CI status, read from the run: three legs are red — Rust tests, Rust tests (macOS), GNU regression goldens and canaries — and all three fail on the same single test, api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell (consumer_tests.rs:2911); everything else in those runs is green, including the CLI/functional/cross-target/Windows-compile legs and both niu-canary legs. Two things for captain review to reconcile: (a) whether that single red is the known lib-only-run missing-bin trap or something this diff touches — the new stem is #![cfg(windows)], so it never runs on Linux/macOS CI; (b) your local report reads 1349 pass / 1 pre-existing failure issue2084, which is a different test from CI's issue2875 — the same mismatch appeared on #3509 and needs the same reconciliation.

One scope note for review: the change lands in the shared restore helper, so it decodes DATA_SQUOTE for every caller, not only the two pipeline faces named in the body — review will check no caller needs the carrier to stay encoded.

Per the owner's rule for external PRs, this is queued for captain review; I won't merge or request changes here. CI is being watched.

@caomengxuan666

Copy link
Copy Markdown
Member

队长复核:PASS ✅

外部贡献(@Catapult291),队长复核结论如下(复核车道独立核查 + 队长抽查):

缺陷与修法成立。 管道成员参数词里「活反引号命令替换 + 撇号」混排时,外部子进程 argv 收到未还原的 DATA_SQUOTE 载体字节(0x17):GNU/期望 member's,旧行为 member\x17s——因为成员的参数词展开在外部 spawn 的 argv 恢复阶段漏调了既有的共享还原 helper。本 PR 在 restore_command_substitution_output 的成员路径补上这一行调用,修在机制点(共享 helper 的最后一个漏接调用方),不是个案补丁。

证据:

  • diff = src/executor/execution_misc.rs 补一行还原调用 + 新 pin tests/d11_pipeline_squote_carrier_regressions.rs(6 格,#![cfg(windows)])。
  • 调用方审计:该共享 helper 的全部消费面已逐一核过,无其它漏接点(subshell/assignment/od/xargs/grep -oP 等相邻面均已正确还原)。
  • pin 双向基线:head 6/6 绿;base(5219be90)+ 同一 pin = 恰好目标格红(成员 argv 含字面 0x17),fail-first 成立。
  • CI(run 43475995953,队长侧按名核对日志):GNU goldens 1349/1、Rust 0/1、macOS 1242/1——三处失败全部是 master 基线既有的 issue2875 单格(tests: lib-only runs false-red the issue2875 procsub cell when no rubash bin is built #3292 已知类),与基线 run 43405733520 同名同数,无新增失败名。
  • 冲突面:与现行 master 交集为空,无需 update-branch。

小注(不挡合入): PR 正文无删除节、无 issue 引用(自引 niubash 缺陷清单 D11)。外部 PR 按证据合入;正文卫生下次请补删除节。

Refs-only 性质:本 PR 不自动关闭任何 issue,队长合入后计数不变。

@caomengxuan666
caomengxuan666 merged commit 0ef814f into unixwin:master Nov 14, 2026
12 of 15 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…2847) (#3556)

Fixes #2847

## 修了什么

`scripts/check-api-ledger.py` 的 §6 校验从「子树里有同名声明」改为「记录的路径就是真实导出路径」:

- `item rubash::a::b::Name`:从 `src/lib.rs` 起逐段解析,每一段必须是 `pub mod`(内联或文件,含 `#[path]`)或把模块 `pub use` 出来的再导出;末段 `Name` 必须在该模块**顶层**以 `pub` 声明(fn/struct/enum/trait/type/const/static/union/mod),或被该模块 `pub use` 再导出(具名、`as` 改名、glob;glob 目标可以是私有模块,如 `parser` 的 `pub use nodes::*`)。只认裸 `pub`,`pub(crate)` 不算对外面。
- `variant` / `method`:其所属类型路径按同一解析器校验(此前 method 完全不看类型路径)。
- 诊断区分两种失败:`declared in the tree but not exported under rubash::…`(路径错)与 `not found in tree`(符号没了)。
- 源码级近似:先抹掉注释与字符串/字符字面量,再按花括号深度判定「顶层」;不追宏生成的条目(真遇到会大声失败、需人工处理)。
- 自检(`--self-test`)新增一组:真实导出路径(具名/改名/私有模块 glob/`#[path]`/根再导出/子模块路径)必须过;未再导出、穿私有模块、类型路径错的 item/variant/method 必须各自失败。

## 删了什么

`item_exists` 原先的「模块子树 rglob + 声明模式」判定(即 issue 所说的盲区)。`PUB_DECL_PATTERNS` 只保留用于失败诊断(区分「路径错」与「不存在」)。

## 依据

工程面,无 GNU 锚。

## 验证

- issue 复现:取 #2850 之前的树(`4f0d493c~1`,`CandidateKind` 尚未在 `src/api/mod.rs` 再导出):
  - 旧脚本:`all 279 ledger symbols present`,rc=0(假绿)
  - 新脚本:5 条失败(`item rubash::api::CandidateKind` + 4 个 variant,均为 `declared in the tree but not exported under rubash::api::CandidateKind`),rc=1
- 当前 master:`all 287 ledger symbols present`,rc=0;`--niu D:/repo/niubash`:287 present、97 consumed paths recorded,rc=0。
- `--self-test` rc=0(四段自检全部通过)。
- 运行时间与旧脚本持平(约 13.5s,瓶颈仍是原有的 method 全树扫描)。
- 另带一个仅格式化提交:`tests/d11_pipeline_squote_carrier_regressions.rs`(#3511 在 master 留下的 fmt 漂移,pre-commit hook 必红;与 #3531/#3547 中的同一 hunk 相同,合并无冲突)。

## Owed

- `docs/api-ledger.md` §5 第 1 条仍写「proves presence by declaration patterns only」,现已不准确;但该文件要求与 niubash 副本逐字节相同(canary `cmp`),需 rubash/niubash 成对改,本 PR 未动。
- 未在 CI(`niu-canary.yml` 的 `ledger` / `pairing` job)上实跑,仅本地 Windows Python 3 运行。


## 队长复核(合入时)

- 判词 PASS:L1–L8 一手跑过全绿(287/287、--self-test、复现树双向对照旧假绿 279 / 新 5 缺失、--niu 97 consumed、两份账本 sha256 identical)。
- CI run 43560449915:3 fail 逐名 = issue2875 ×2(goldens、macOS)+ issue2859 Linux-only;issue2859 按 #3292 类确认为 VOID(同头 macOS/goldens 该 cell 绿、零 Rust 产品代码、不碰 jobs/sleep 面)。
- 交集 ∅(merge-base 8b48c16 = live tip),无需 update-branch。
- 合入体:接受正文 Fixes #2847,#2847 随合入自动关闭。
@qwased

qwased commented Nov 14, 2026

Copy link
Copy Markdown

Independent repro from a Pi integration running the shipped Niubash 1.5.0 (rubash git 29bbf524, Windows 11), plus two details for the rollout:

  • The pre-fix leak is not backtick-only in this shape: a pipeline member whose double-quoted word carries $(echo now) and an apostrophe also delivers it\u0017s now to the child on 1.5.0. Without the pipeline it is it's now.
  • niu --ec <base64> reproduces as well, so --ec is not an escape hatch for this class.
  • The fix is on rubash master (0ef814fb), but niubash master's scripts/release/rubash-pin.json is still fc76209b (2026-11-04): git merge-base --is-ancestor 0ef814fb fc76209b is false. Binaries built from current niubash master still carry the defect until the pin bumps and a release ships it.

This matches the pre-fix analysis in the PR; the $() observation is the only addition. Thanks for the fast fix.

caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
GNU builtins/cd.def:370 prints `no_symlinks ? temp :
the_current_working_directory`, where temp is cd.def:360's
sh_makepath(unit, dirname) join (lib/sh/makepath.c:66). Under -P the
announcement is that join verbatim, so a relative CDPATH unit echoes a
relative path and `./`/`..` components stay; rubash routed it through
the logical destination and absolutized it. The join is now built
textually (unit + `/` unless the unit ends in one + operand) instead of
Path::join, whose separator is the host's.

Also rustfmt tests/d11_pipeline_squote_carrier_regressions.rs, which
landed unformatted on master (#3511) and fails the pre-commit check.

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
…TIMEFORMAT (Refs #3393) (#3537)

GNU lib/readline/histfile.c:384 read_history_range arms
history_multiline_entries only when the file starts with a timestamp
line AND history_write_timestamps is set (variables.c:6177
sv_histtimefmt: HISTTIMEFORMAT exists). The counter is never reset.
rubash regrouped whenever the file had timestamps. Model the sticky
counter on SessionHistory and feed it the read-time variable state;
the interactive startup load takes the same state instead of a
hard-wired armed read.

The issue1669 pin chained unarmed reads after an armed one in one
process, which only matched the old non-sticky model; GNU 5.3.20
regroups there. Split the unarmed phases into fresh processes.

Also rustfmt the d11 stem (master drift from #3511) so the fmt hook
passes.

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
…k (Refs #3489) (#3547)

* fix(read): re-tag carrier bytes on the C-locale byte-domain write-back (Refs #3489)

read_split.rs byte_domain_value emitted every byte < 0x80 as a bare
char when it turned single-byte-locale fields back into storage text,
undoing tag_read_carrier_text. Under LC_ALL=C (bats runs formatters
under env -i) ESC stopped matching $'\e' patterns, so the junit
formatter's xml_escape CSI strip left [0m/[K behind; 0x14 became `\`,
0x1f `$`, 0x11/0x13 vanished. The write-back now goes through
bytes_to_shell_text, the storage-domain inverse of
shell_text_to_raw_bytes, which re-forms UTF-8 and re-tags carriers.

GNU: builtins/read.def:838-845 escapes CTLESC/CTLNUL and
read.def:1127 / :1061 dequote_string undoes it, so the bound value is
byte-identical to the input in every locale.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* style(tests): rustfmt the d11 pipeline squote stem

master fmt drift from #3511 makes `cargo fmt --check` (the pre-commit
hook and CI fmt) fail on every branch; formatting only, no test change.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
… (#3554)

* fix(hash): re-validate relative hash entries on every read (Refs #3359)

GNU hashcmd.c:126 phash_search is the single read of a remembered
location for execution (findcmd.c:365 search_for_command), type /
command -v (type.def:353) and hash -t (hash.def:284). For a stored
relative path (HASH_RELPATH) it serves the ./-prefixed form when
executable and answers NULL when the stored ./path's directory is the
cwd and the file is gone (hashcmd.c:146-187), so the lookup re-walks
PATH. rubash applied that rule only to hash -t and served the stored
spelling unvalidated everywhere else; `hash NAME` also stored the
cwd-anchored path instead of the search's as-written join
(hash.def:213-225 add_hashed_command).

- builtins::hash::phash_search / phash_search_spelling: one shared
  implementation, probes anchored at the session cwd.
- path::find_user_command's hash-mirror consult goes through it; a
  refused entry drops the stale PATH-scan memo and walks PATH.
- type/command -v describe faces read through phash_search.
- record_command_resolution overwrites a refused entry (phash_insert,
  times_found = 1) instead of bumping it.
- `hash NAME` records recorded_resolution_spelling and syncs the mirror.

Also rustfmt tests/d11_pipeline_squote_carrier_regressions.rs, which
landed unformatted on master (#3511) and fails the pre-commit check.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs(hash): point the unmodelled HASH_CHKDOT arm at rubash#3551 (Refs #3359)

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: root <[email protected]>
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…3372) (#3565)

GNU redir.c:298 redirection_expand gives every redirect its own expanded
bytes and redir.c:702 redir_open opens them verbatim, so in
`: >"$a" >>"$b"` a raw-byte x<9C> and a genuine x<U+009C> (same folded
string) land as two files. #3368 made the create funnel read the
redirect-node spelling record; the append funnel still read the
folded-string record and reopened the other redirect's spelling.

- shell_options: open_append_target_for(Option<&Redirect>, target); every
  filesystem arm resolves through the node record when a node is given
  (plain funnel otherwise, never the string-keyed record).
  probe_output_redirect_append takes the node too, for both its FIFO
  stat and its open.
- builtin_redirects / external_redirects / redirection: the append call
  sites that hold the node pass it.
- mod.rs: correct the field comment that claimed a no-transport outcome
  clears the string-keyed record (the code never removes it).

Also rustfmt tests/d11_pipeline_squote_carrier_regressions.rs, which
landed unformatted on master (#3511) and fails the pre-commit check.

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…y (Refs #3305) (#3559)

read_coproc_stdout compared the delimiter on every byte and counted the
-n/-N budget per byte. GNU builtins/read.def:834 compares the stream
byte against the first byte of the -d word only at a read_mbchar unit
start, and read.def:884-886 counts the budget per completed unit
(post-escape). The fd-table serves already replay that loop through
FdRecordScan; the coproc serve now drives the same scanner, dropping
the delimiter like they do. ReadEscapeTracker (its last user) is gone.

Also rustfmt the d11 stem (master drift from #3511) so the fmt hook
passes.

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…s GNU does (Refs #3457) (#3549)

GNU runs every startup file through builtins/evalfile.c:339
maybe_execute_file with FEVAL_ENOENTOK: ENOENT is not diagnosed
(evalfile.c:120) and returns 0 (evalfile.c:130); EACCES and other open
failures still go through file_error, and a directory is reported as
`%s: is a directory` (evalfile.c:133-138). run_init_file diagnosed
ENOENT and, on Windows, reported a directory as `Permission denied`.

The diagnostic name prefix is untouched (PR #3447 owns it). Also
rustfmt the d11 stem (master drift from #3511) so the fmt hook passes.

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:carrier in-band carrier/marker protocol: markers.rs, decode boundaries, PUA/C0 bug Something isn't working family:M1 taxonomy M1: producer/carrier encoded, consumer forgot to decode P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants