Skip to content

fix(executor): decode produced carriers at the subscript eval expand (Refs #3613) - #3629

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3613-compound-declare-triple-expand
Nov 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3613-compound-declare-triple-expand

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #3613.

declare -a b=([${x}]=v) with y='echo 1'/x='$y' reported error token <E30A>y (PUA carrier leak) and bound b=() — GNU reports `echo 1` and leaves b declared-but-unset (declare -a b).

GNU layering (arrayfunc.c:1368 array_expand_index → expand_arith_string → evalexp): the element word expands once (${x} → $y), the subscript expands again ($y → `echo 1`), and evalexp fails on the junk token → evalerror → DISCARD before the bind, keeping the -a mark.

Changes:

  • expand_arithmetic_subscript_mut (and the array_expand_once verbatim arm of eval_indexed_subscript_expression) decodes the E30x produced-data carriers on input so the expand-again pass sees plain text — the produced $ expands again and the produced ` is data.
  • declare_local's rewrite Err arm abandons the operand on evalerror_pending (same arm as the failglob gate) while recording the ARRAY/ASSOC + DECLARED_UNSET marks — declare -p b prints declare -a b.

Verified byte-identical to GNU (modulo the repo-wide arithmetic syntax error prefix difference vs 5.1): token `echo 1`, rc=1, declare -a b for the declare arm; b=() still binds for plain b=([${x}]=v); a[${x}]=v reports $y on both; set -u unbound subscript aborts identically. 4 new regression pins in tests/issue3613_compound_declare_triple_expand.rs.

…(Refs #3613)

declare -a b=([${x}]=v) with x='$y', y='`echo 1`' reported error token
$'`e30a`y' (PUA carrier leak) and bound b=() — GNU reports `echo 1`
and leaves b declared-but-unset.

GNU: expand_words_no_vars expands the element word (${x} -> $y);
array_expand_index's expand_arith_string (arrayfunc.c:1368) re-expands
($y -> `echo 1`); evalexp fails on the junk token `echo 1` ->
evalerror -> DISCARD before the bind, keeping the -a mark.

- expand_arithmetic_subscript_mut (+ its array_expand_once arm) decodes
  the E30x produced-data carriers on input so the expand-again pass sees
  plain text; produced bytes re-mark themselves during that pass.
- declare_local's rewrite Err arm now abandons the operand on evalerror
  (same arm as the failglob gate) while recording the ARRAY/ASSOC +
  DECLARED_UNSET marks GNU keeps — declare -p b prints 'declare -a b'.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT s1】

PR #3629 第1轮 — 建议:PENDING(机制与钉腿全证;卡在 #3608 合入后的文本冲突,需 rebase 后重报)
head: ad806d8 base(merge-base): 27e1d0d 文件: 4 个 +142/-3
关联 issue: #3613(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • 载体重解码贴 GNU 重解析模型成立:arrayfunc.c:1370 array_expand_index 把下标文本(compound-declare 臂里未经 CTLESC 保护的产文)喂给 subst.c:3981 expand_arith_string 的 expand_word_internal 单遍——产生的 $ 会再展开、 `` 为数据。decode_subscript_reparse_markers 只解 ASSIGN_SQ_/ASSIGN_EXPANSION_(E30A-E30F)载体,不解 DATA_DOLLAR(\x1f)——这正好保住 `a[${x}]=v` 臂的 `$y` token(钉 4 绿证)。declare_local.rs Err 臂:evalerror_pending(arithmetic/mod.rs:1476-1583 仅在算术 eval 失败置位、ast_exec.rs 各命令边界清零)→ 弃 operand 但打 ARRAY/ASSOC+DECLARED_UNSET 标 → `declare -a b`,贴 GNU evalerror→DISCARD(arrayfunc.c:1381-1388)先于 bind 的语义;非 evalerror 的 bad-subscript 仍落 `partial`(break+bind),门控无过宽。
  • diff 里可疑/无关改动:无。正文 "Closes compound-declare 三重展开:错误 token 泄漏 PUA 载体且空数组被创建(GNU 未赋值) #3613" 为作者原文(关单口径备注,供队长核)。

腿(逐项给数字与名字):

  • 钉自跑 head:issue3613_compound_declare_triple_expand 4 passed / 0 failed
  • fail-first:base(27e1d0d) 上 1 passed / 3 failed,红名 = {declare_compound_evalerror_leaves_name_declared_unset, declare_compound_triple_expansion_reports_expanded_token, plain_compound_evalerror_still_binds_empty_array};绿的 1 名 indexed_element_assign_keeps_produced_dollar_literal 为守卫钉(base 上 $y token 本已正确),红名集合与修复面精确对应,fail-first 有效
  • lib 双边:head 失败名集 {issue2084_session_end_restores_host_process_state} / base 失败名集 {issue2084_session_end_restores_host_process_state} / 差集 ∅(env-bound,consumer_tests.rs:712/782 host-env 检查,两侧同败)
  • -D warnings:lib+bins rc0 零警告
  • 卫生:rustfmt --check PR 4 文件 clean;marker-lint OK (117 consts / 268 sites);utf8-hygiene clean
  • CI:3 红任务逐个归因 — "GNU regression goldens and canaries"、"Rust tests"、"Rust tests (macOS)" 各只红 1 名 issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:2911 签名)= 已知基线
  • GNU 对照:WSL GNU bash 5.3.20(1)-release(脚本存 target/audit-s1/probe3613{a,b,c}.sh):declare -a b=([${x}]=v)(y='`echo 1`' x='$y')→ GNU rc1 token `echo 1` + declare -a b / head 全同;b=([${x}]=v) → token `echo 1` + b=() / head 同;a[${x}]=v → token $y + a not found / head 同。master 复现缺陷:token 漏 <E30A>y PUA + b=()。

合流阻塞(PENDING 原因,非机制缺陷):

F 点:无(机制层无缺陷;阻塞为合流态)

续作记录:本轮未动代码(冲突处置归作者/调度)

未跑/VOID 的腿:无

…#3613)

Conflict: src/executor/arithmetic/mod.rs only. #3608 (4e2c529)
replaced the two-state array_expand_once gate in
eval_indexed_subscript_expression with the three-state `expand` split,
so the #3613 carrier decode moves into the `else if array_expand_once`
arm (AV_NOEXPAND: text stays verbatim for evalexp) and stays at the
expand_arithmetic_subscript_mut entry (the expand_arith_string pass
must re-lex decoded bytes). #2701's `${...}` fatal latch from master
now reads the decoded text — that is what GNU's expand_arith_string
(arrayfunc.c:1368 -> subst.c:3981) re-reads.

Both pin stems green after the merge: issue3613 4/4,
issue3522_unset_indexed_backquote_subscript 22/22, issue2701 12/12.
…xpand (Refs #3613)

Advance the branch onto the current master tip so the #3608 expand-gate
merge below applies cleanly and the CI matrix runs on today's base.
Conflict-free: master's new commits touch parser/read/tests only.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT s1】

PR #3629 第2轮 — 建议:PASS(冲突已解,全腿在解冲突后的 head 上复证)
head: 4c28cbe base(merge-base): 1a51222 文件: 4 个 +142/-3(合流后净差不变)
关联 issue: #3613(状态:open,我核过的时间:2026-11-16 本地)

合流处置(本轮唯一动过的东西):

机制核查(复证,未改判):

  • arrayfunc.c:1368 array_expand_index → subst.c:3981 expand_arith_string(subst.c:4006 td.flags = W_NOPROCSUB|W_NOTILDE)单遍;AV_NOEXPAND 时 text 原样进 evalexp。declare_local Err 臂 evalerror → DISCARD 先于 bind(arrayfunc.c:1381-1388):名字留属性标、不 bind(declare -a b),而 err_badarraysub 仍 break+bind(declare -a b=())。
  • 可疑/无关改动:无。

腿(逐项数字与名字):

  • 钉自跑(head 4c28cbe):issue3613_compound_declare_triple_expand 4 passed / 0 failed。合流回归钉:issue3522_unset_indexed_backquote_subscript 22 passed / 0 failed(fix(executor): evaluate already-expanded indexed subscripts without re-expansion (Refs #3522) #3608 面未回退);issue2701_question_assign_outside_word_pipeline 12 passed / 0 failed(被解冲突的函数另一侧)。
  • fail-first(base 1a51222 + PR 钉原样):1 passed / 3 failed;红名 = {declare_compound_evalerror_leaves_name_declared_unset, declare_compound_triple_expansion_reports_expanded_token, plain_compound_evalerror_still_binds_empty_array};绿 = indexed_element_assign_keeps_produced_dollar_literal(守卫钉,base 本已正确)。与 PR 声称一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1354 passed / 1 failed)/ base 1a51222 失败名集 {同名}(1354 passed / 1 failed)/ 差集 ∅。
  • -D warnings:cargo check --lib --bins rc0、0 警告。--all-targets 红是基线既有(base 同红:issue1276 unused import Stdio、issue2737 dead_code),不记本 PR。
  • 卫生:rustfmt --check 3 个改动文件 OK;marker-lint OK(117 registry consts / 268 allowlisted sites);check-utf8-boundary-hygiene clean。
  • CI(head 4c28cbe,run 43851153259)逐名归因:
    • Rust tests(fail)→ 只红 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:3503 前置条件:无 rubash 二进制)= 已知基线。
    • Rust tests (macOS)(fail)→ 只红同一个 issue2875 = 基线。
    • GNU regression goldens and canaries(fail)→ 只红同一个 issue2875(1354 passed / 1 failed)= 基线。
    • Regression pin stem census(fail)→ 97 名;与 master 同类 run(d3f1ccef,job 133212453399)逐格对比:96 名完全相同(该 96 名即 scripts/ci-pin-exclusions.txt 记录的已知红普查基线),唯一多出的是 issue2771_posix_function_tempenv_conversion::issue2771_posix_in_function_conversion_reaches_global_cell——TIMING flake:该钉断言 SECONDS=100 : 后 sleep 1 读 101,运行器负载下读成 102(left "top-after: 102" / right "top-after: 101"),探针里没有下标运算,与 PR 4 文件无关;同 stem 另 3 个测试全绿。master 另一条 run(1c811bc7)同一 job 红名单有 99 名且与本次仅部分重合,证明该 job 红集合本身逐 run 抖动。
    • 其余 7 个 job 全 pass(API ledger tripwire / Compatibility CLI / Cross-target darwin+linux/android / Shell functionality / Windows tests compile / niubash builds)。
  • GNU 对照:WSL GNU bash 5.3.20(1)-release(脚本 target/audit-s1-merge/{a..g}.sh,同一脚本文件喂两侧):

相邻残差(base 已存在,非本 PR,建议另开工单,不在本条阻塞):

F 点:无

续作记录:只做合流,未改产品语义。commit 242085a(解 #3608 三态门冲突)、4c28cbe0(追平 master 1a51222);新 head 4c28cbe(远端已确认为此 oid)。

未跑/VOID 的腿:无

@caomengxuan666
caomengxuan666 merged commit 354064e into master Nov 16, 2026
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compound-declare 三重展开:错误 token 泄漏 PUA 载体且空数组被创建(GNU 未赋值)

1 participant