Skip to content

fix(expansion): only run compound expansion on parser-marked compound assignments (Refs #3034) - #3056

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3034-assignment-paren-expansion-leak
Nov 8, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3034-assignment-paren-expansion-leak

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3034

现象

x=v1.0; y="($x)"; printf '%s' "$y" | od -An -tx1:GNU 存 (v1.0),
rubash 存 (\x10"v1.0")——泄漏 ARRAY_FIELD_SPLIT_MARKER(0x10)+
一对存储引号。同样泄漏:y="(${x})"、y='('$x')'、多展开、含空格值、
链式 y2="($y)"、参数形词 echo "y=($x)"、前缀赋值、eval。这是
#3005(__git_ps1 分离头症状)之根:b="$(git describe …)"; b="($b)"
的第二步即此形状。

根因

复合认领(compound-claim)调用缺失复合判定。expand_compound_positional_at_assignment /
expand_unquoted_parameter_compound_assignment 实现 GNU
expand_compound_array_assignment(arrayfunc.c:557),却被调用在任何
括号形值上:三处赋值展开调用点(assignment_expansion.rs 的
expand_assignment_value_inner、expand_word.rs 的
expand_plain_assignment_word、parameter_core.rs 的
expand_word_mut_with_context)认领前从不查解析器的复合判定。
y="($x)" 的 ( 在引号内、不是复合赋值,却被认领为元素表,其
compound_field_split_transport 产物 \x10"v1.0"(assignment_helpers.rs:976)
不经拆分/解码就原样存为标量值。

仪器证据(基底二进制,RUBASH_DBG_AAV=1):
[ECPAT] value="($x)" expanded="(\u{10}\"v1.0\")"。

修法

三处调用点统一加复合认领门:仅当值带 COMPOUND_ASSIGNMENT_MARKER
(U+E31A)时才调用两只复合展开函数;否则落入一般赋值串展开
(subst.c:4357 expand_string_assignment)。门用的就是解析器自己的
复合判定(GNU 的同一判定),即「复合展开只跑在解析器已判定为复合赋值
的词上」这一不变量——不是症状黑名单。门内 marker 拼回保持原样。
未动:eval 的 bare-flatten、declare -a d="(a b)" 的 declare 重解析
路径、continuation.rs、docs/api-ledger.md。

GNU 锚点

  • parse.y:5648-5657 read_token_word(复合判定:仅 = 后紧跟未引用
    ( 才进 parse_compound_assignment)
  • parse.y:7104 parse_compound_assignment
  • arrayfunc.c:557 expand_compound_array_assignment
  • subst.c:4357 expand_string_assignment

本 PR 删除了什么

无删除。 本 PR 只做加法与门控收窄:

  • 不删除任何公开 API、测试、文档或功能。
  • 唯一「减法」是行为面收窄:未带 COMPOUND_ASSIGNMENT_MARKER 的括号词
    不再进入复合展开——这正是被修的 bug 本身(此前误认领的路径)。
  • 净行数:+269/−43 = +226(钉 +199;修法 3 文件 +70/−43)。
    −43 行中无整段删除,均为门内化简(if compound_assignment { marker } else { "" }
    在门内恒真,化为直接拼 marker)与注释调整。

车道自验证据

备注

…e (Refs #3034)

Regression pin: tests/issue3034_assignment_paren_expansion_regressions.rs
(13 cells). Quoted scalar words whose parens are literal data
(y="($x)", y="(${x})", y='('"$x"')') must store the plain
parenthesized value; the __git_ps1 detached chain (b="$(...)" then
b="($b)", rubash#3005 root) must render ((v1.0)); genuine compound
assignments (y=($x), y=("$x")) stay arrays. See the file header for
the GNU anchors (parse.y:5648-5657, parse.y:7104, arrayfunc.c:557,
subst.c:4357).

Refs #3034
… assignments (Refs #3034)

expand_compound_positional_at_assignment /
expand_unquoted_parameter_compound_assignment implement GNU
expand_compound_array_assignment (arrayfunc.c:557) but were called on
ANY parenthesized value. A quoted scalar word such as y="($x)" —
whose parens are literal data inside double quotes — was claimed as
an element list, and its products ride the
ARRAY_FIELD_SPLIT_MARKER-tagged field transport, which leaked verbatim
into scalar storage: (\x10"v1.0") instead of (v1.0). Same shape via
y='('"$x"')', argument words (echo "y=($x)"), and prefix
assignments. Gate both claim calls on the parser's compound decision
(COMPOUND_ASSIGNMENT_MARKER, U+E31A): only an unquoted '('
immediately after '=' starts parse_compound_assignment
(parse.y:5648-5657, parse.y:7104); a quoted scalar takes the
assignment-string path (subst.c:4357 expand_string_assignment). This
is the root of #3005 (__git_ps1 detached chain).

Regression pin: tests/issue3034_assignment_paren_expansion_regressions.rs
(13 cells; fail-first on true base 30ddc12 = 2 passed / 10 failed,
exactly the bug faces).

Refs #3034
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 8, 2026 02:27
@caomengxuan666
caomengxuan666 merged commit 873b30e into master Nov 8, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 9, 2026
…#3143)

Fixes #2907

生态链钉入仓:真实 git contrib 脚本(git-completion.bash / git-prompt.sh,GPL 不入仓、宿主发现)的 live 入口端到端链钉——链 A 驱动已注册补全入口 `__git_wrap__git_main`(含 A15 直调 `__git_main`),链 B 在八态仓库上渲染 `__git_ps1`(含无参打印形与 pcmode 形);同仓库、同 driver 分别在 rubash 与 GNU bash 5.3.20 oracle 下运行,stdout 逐字节一致、stderr 归一脚本路径后逐字一致。同文件第二钉复核 mvdan-n 16 个解析夹具的 `-n` 退出码与 oracle 逐个一致(559 片段差分是否接 CI 仍归 #3033 裁定,本 PR 不预断)。本钉即 eco-2907 两处已修分歧的链级回归钉:B6 格 = #3034(PR #3056)真实命中形,A15 stderr 格 = #3035(PR #3047)真实命中形。

本 PR 删除了什么:无(纯测试与夹具新增)。净行数 +645/−0,4 文件:tests/issue2907_git_contrib_chain.rs、tests/fixtures/ecosuite/git-contrib/{driver,make-repos}.sh、tests/fixtures/ecosuite/MANIFEST.md。
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.

1 participant