Skip to content

fix(state-views): snapshot seeded array/assoc vars from their mirror storage, not the import-seeded scalar cell (Refs #3083) - #3101

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3083-snapshot-dynamic-rhs-prefix
Nov 8, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3083-snapshot-dynamic-rhs-prefix

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #3083

队长复核 PASS(独立 clone 全腿亲验,见 ~/workspace/review-3083/verify.log)。

问题与根因

Session 快照(views().inspection(),DAP variables 同源)在四个启动种子数组/关联名(BASH_VERSINFO、DIRSTACK、BASH_ALIASES、BASH_CMDS)上泄漏镜像存储串原文——含 U+001D 词前缀字节——且值类型报为 Scalar。

字节级核实后根因与立案时的假设不同:前缀是真 U+001D 字符而非字面文本 \x1d,也不是 declaration_scalar_rhs 产生。init 把四名以存储形态种入 env 表,Executor::new 经 VariableStore::from_environment 把整张种子表绑成 exported Scalar,typed cell 里于是躺着镜像存储串的逐字副本;capture_variable 先信 typed cell,快照遂泄漏。DIRSTACK/BASH_ALIASES 的镜像本身还是出生快照(pushd/alias 不刷新),活值由 parameter_array_storage 在命名访问时合成(GNU variables.c:1619 get_dirstack 同形)。

GNU 锚点:导入只绑进程环境的纯标量(variables.c:368 initialize_shell_variables);自家数组 cell 出生即 ARRAY 对象(variables.c:1018 make_vers_array;variables.c:1882 init_dynamic_array_var("DIRSTACK", get_dirstack, assign_dirstack))。

修法

修捕获路径,不动渲染边界(#3074 的渲染解码未碰,无渲染侧剥前缀):在 capture_variable 的通用路径值匹配里新增一臂——array/assoc 标记名、typed cell 为纯 Scalar、且镜像存在时,经 parameter_array_storage(镜像缺席臂本就为同组名字咨询的物化合成面)捕获,合成为空时回退镜像文本。结构化 typed cell 仍优先,用户数组捕获与此前逐字一致。

本 PR 删除了什么

无删除。第二个提交为纯新增一支捕获臂(+37 行,含注释);第一个提交为新增测试文件。被否决的立案假设(字面文本说 / declaration_scalar_rhs 说)只存在于讨论中,未落代码,无可删。

验证(队长复核,独立亲验)

  • 钉 tests/issue3083_snapshot_array_values.rs:头树 4/0;fail-first(终版钉移植干净基底 9d155da3)1p/3f,失败恰为三缺陷格、对照格绿;基底失败输出坐实根因(typed Scalar 躺镜像存储串、真 U+001D)。
  • lib 双边:头与基底均为 1206/0/4,失败名集两边皆空,全等。
  • 邻茎:marker_leak_golden 21/0、session_api 19/0、typed_cell_coherence_fuzz 2/0。
  • RUSTFLAGS="-D warnings" rc=0;fmt rc=0;utf8 hygiene clean;check-marker-literals OK(117 consts / 265 sites,无新增 allowlist);CR 无。
  • GNU 探针:四名 declare -p GNU vs 头二进制同 cwd 逐字节 SAME,双边 rc=0、头 stderr 空。
  • 改动面审计:恰 2 文件 +223/−0——state_views.rs +37 为单一新臂(typed 臂之前),渲染边界零改动;未碰 continuation.rs 与 api-ledger.md。
  • CI 现头全集 10 pass + 1 skipping。

残余(均已立单,不挡合入)

@caomengxuan666
caomengxuan666 force-pushed the fix/3083-snapshot-dynamic-rhs-prefix branch from c48a090 to 8d7e7a2 Compare November 8, 2026 07:22
…ars (Refs #3083)

The inspection snapshot of BASH_VERSINFO / DIRSTACK / BASH_ALIASES /
BASH_CMDS currently carries the raw env-mirror storage string as a
Scalar (the STORAGE_WORD_PREFIX-led storage form for the indexed
pair, "()" for the assoc pair) instead of the array value the
snapshot's own declaration text renders. GNU keeps these as real
ARRAY cells from birth (variables.c:1018 make_vers_array;
variables.c:1882 init_dynamic_array_var for DIRSTACK with
get_dirstack at variables.c:1619), and its environment import
(variables.c:368 initialize_shell_variables) binds only plain
scalars. Four tests drive the public Session inspection face:
seeded indexed pair, live DIRSTACK after pushd, seeded assoc pair
plus a live alias, and a user-binding control group.

UNVERIFIED-BY-CAPTAIN
…ializing storage arm (Refs #3083)

capture_variable trusted the typed cell first, but for the four
startup-seeded array/assoc names (BASH_VERSINFO, DIRSTACK,
BASH_ALIASES, BASH_CMDS) the typed cell is a plain Scalar holding a
verbatim copy of the mirror storage string — VariableStore::
from_environment binds the whole init-seeded table as exported
scalars, prefix byte and all — so snapshots (Session inspection,
DAP variables) leaked the raw storage form, U+001D word prefix
included, typed as a scalar.

GNU's import binds only the process environment's plain scalars
(variables.c:368 initialize_shell_variables); its own array cells
are born as ARRAY objects (variables.c:1018 make_vers_array;
variables.c:1882 init_dynamic_array_var("DIRSTACK", get_dirstack,
assign_dirstack)), and the stack's live value is composed on access
(variables.c:1619 get_dirstack).

Fix the capture path, not the render boundary: when an
array/assoc-marked name's typed cell is a plain Scalar and a mirror
exists, capture through parameter_array_storage — the same
materializing arm the mirror-absent capture already consults for
exactly these names — falling back to the mirror text. Structured
typed cells still win, so user arrays capture exactly as before.
No render-side stripping; #3074's decode is untouched.

Pin: tests/issue3083_snapshot_array_values.rs (previous commit) —
1 passed / 3 failed on base 9d155da, 4/0 with this fix.
@caomengxuan666

Copy link
Copy Markdown
Member Author

车道残余立案(均标签/assign/1.5.1 齐):正文提到的 alias 后 declare panic 已立 #3107;同根 attrs 面(快照 exported 误报)已立 #3108。两者均不在本 PR 范围。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 8, 2026 08:40
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