Skip to content

fix(#824): decode-boundary leak asserts fired on user-literal marker text (HD1 in declare -p, guard in xtrace) - #838

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/824
Oct 19, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/824

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #824. Two commits' worth of scope in one: the shared-decoder fix, the #729 entry-inventory update, and the CI gate mechanism.

Site 1 - HD1 through declare -p value rendering

x=a__RUBASH_HD1__b; declare -p x panicked a debug build: QUOTED_HEREDOC_MARKER leaked to output (src/locale.rs). The declare -p path feeds stored values through decode_to_visible_text (builtins/declare/storage.rs display_text/quote_array_element_value), and __RUBASH_HD1__ is plain typeable ASCII - the user's own data. The golden assert at the decoder's output read "named marker in output => decode failed", but a live HD1 tag is consumed at heredoc-body execution before anything is stored or displayed, so an occurrence on this boundary is user data by contract. Same entry fired COMSUB_PAYLOAD_PREFIX leaked for typed x='__RUBASH_CSB1_41;'. GNU bash 5.3.0 (WSL stdin oracle) prints both texts verbatim; so did rubash in release - only the debug assert was wrong.

Site 2 - guard sentinel through xtrace

set -x; v=$'\uE314Z'; echo "$v" panicked a debug build: PARAM_WORD_BACKSLASH_GUARD leaked to output. The U+E314 char is the user's own data, E400 literal-char-escaped at entry (rubash#735) and restored verbatim by the decode's E400 arm - exactly what the existing (failing-on-base) xtrace_carries_no_markers child asserts. A bare guard cannot survive the scan (the guard arm consumes each guard with its protected char), so a guard codepoint in the decoder's output is by construction restored user data, never a live guard. The issue's v='a\$b' shorthand maps to this same pre-existing base failure (xtrace_carries_no_markers); the plain a\$b shape itself does not panic on current master.

One class, one boundary - the #729 audit

Both sites are the same unsound pattern: sixteen output-side debug_assert!s in decode_to_visible_text over codepoints every one of which has a legitimate user-data path to that output (C0 bytes ride raw-byte pairs per the registry user_reachable contract; registry-zone PUA chars ride the E400 escape, #735; named ASCII markers are typeable). The audit (ticket methodology: #729 inventory, #823 CA1 precedent) removed the whole block - consume/whitelist/guard decision per family:

#729 3.2 boundary table rows added (src/executor/markers.rs): Display value rendering (#824 audit) and Display xtrace rendering (#824 audit), both whitelisted; the module golden rule is amended to "marker-FREE input" with leak detection at the integration boundary (tests/marker_leak_golden.rs).

Why this class never met a CI gate - mechanism

Debug builds ARE in CI (cargo's dev profile is the default for every cargo test lane), and the panics fire inside the spawned binary. The gaps were: (1) no CI lane ran --test marker_leak_golden - the only suite feeding user-literal marker text to the decode boundaries (rust job ran only --lib + continue-on-error cli_tests; regression runs a different target list); (2) the in-binary asserts self-disable under cfg!(test), so the --lib lane could never arm them; (3) there was no in-repo repro of the two ticket shapes at all. Mechanism added: the rust CI job now runs cargo nextest run --test marker_leak_golden --test issue824_marker_decode_boundary_regressions --profile ci as a hard gate (hermetic, ~0.5s).

Verification

  • New regressions: tests/issue824_marker_decode_boundary_regressions.rs - 8 end-to-end cases spawning the binary (dev-profile build arms the asserts, so pre-fix code fails these): both ticket sites, CSB1, raw C0 byte via xtrace, E301/E30A/E401 PUA sentinels via declare -p, HD1 lookalike, echo path, CA1 stance. Plus 3 decoder units in tests/decode_to_visible_text.rs (pass-through, E400-restored guard data, bare-guard consume).
  • GNU oracle = WSL GNU bash 5.3.0 stdin method: every pinned byte block captured from it; rubash post-fix debug output is hash-identical to pre-fix release output on all 7 oracle scripts (zero non-debug change), and matches GNU byte-for-byte on every repro/lookalike shape except the documented declare -A name=(...) through the line-editor path panics in debug builds: COMPOUND_ASSIGNMENT_MARKER debug_assert (locale.rs) #802 CA1 consume stance (GNU prints a__RUBASH_CA1__b literally; pinned as ab with the rationale).
  • Full suite, --no-fail-fast --test-threads=1, base 992d5c5 vs this branch, bidirectional comm of the failure sets: zero new failures. The one branch-only name (windows_listing_cache_finds_files_that_appear_but_not_ghosts) and its base-only sibling (windows_nohash_mode_memoizes_hits_but_not_misses) are the executor::path cache timing flake family - each passes 3/3 on rerun in its own tree. marker_leak_golden::xtrace_carries_no_markers fails on base and is fixed on the branch.
  • cargo fmt --check clean. Rebased on origin/master (992d5c5) - the delta's own suites (parameter_transform_tests etc.) re-verified green.

Residuals observed during the audit (pre-existing, non-debug, out of scope - zero-non-debug-change mandate)

  • arr=($'\uE314Z'); declare -p arr renders the E400 introducer in the array element (GNU prints the bare char): a double-escape/restore gap in the array-element storage path.
  • typed __RUBASH_CSB1_41; through printf %s decodes to its payload byte (aA where GNU prints the literal): the comsub-payload decode consumes user-typed prefix text.
  • typed $'\uE30D' is eaten by the assignment-tail unescape (GNU prints the char).
    Each is a non-debug data-shape divergence of the same "marker vs user text indistinguishable" family and deserves its own ticket.

…decode boundary (#824)

User-literal text panicked debug builds at two more decode boundaries
after #802 (marker entry-inventory leak, same #729 methodology):

- x=a__RUBASH_HD1__b; declare -p x  ->  QUOTED_HEREDOC_MARKER leaked
  to output (declare -p value rendering feeds stored user data through
  decode_to_visible_text; the named ASCII marker is typeable text).
- set -x; v=$'\uE314Z'; echo "$v"  ->  PARAM_WORD_BACKSLASH_GUARD
  leaked to output (xtrace carries the user's own U+E314 char, restored
  verbatim through the E400 literal-char escape, rubash#735).

Root cause (one class, one boundary): every output-side debug_assert in
decode_to_visible_text read 'registered codepoint in output => decode
failed', but the #729 carrier-consumer audit shows every registered
codepoint has a legitimate user-data path to that output: C0 bytes ride
raw-byte pairs, registry-zone PUA chars ride the E400 escape, named
ASCII markers are simply typeable. The asserts could only ever fire on
well-formed user data; the scan arms (which consume/decode every bare
marker in-pass) are the actual protocol enforcement, and the integration
leak tests (marker-free inputs) are the actual leak gate.

Fix: remove the assert block, document the per-family output contract,
and record the two display entries (declare -p value rendering, xtrace
word rendering) as whitelisted in the markers.rs 3.2 boundary table.
The __RUBASH_CA1__ consume probe (#802) is untouched; non-debug bytes
are unchanged (release rebuild re-diffed against GNU bash 5.3.0 via the
WSL stdin oracle: byte-identical on every repro and lookalike shape,
and post-fix debug output equals pre-fix release output hash-for-hash).

Mechanism: no CI lane ran marker_leak_golden (the only suite feeding
user-literal marker text to the decode boundaries) and the in-binary
asserts self-disable under cfg!(test) — the panic family never met a
gate. The rust CI job now runs marker_leak_golden plus the new
issue824 repro suite as a hard gate.

Regressions: tests/issue824_marker_decode_boundary_regressions.rs (8
end-to-end cases pinning GNU-oracle bytes: both sites, CSB1, C0 byte,
PUA sentinels, HD1 lookalike, echo path, CA1 stance) and three decoder
units in tests/decode_to_visible_text.rs.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CR 结论:APPROVE-WITH-NITS(PR #838,d41be1ff)

独立评审代理实做复核(自建 worktree、自建 debug/release 双构建、逐字节比对、全量双向测试对比)。无 BLOCKER,可合并;NIT 均不阻塞,可随后续小提交处理。

逐验证点

  1. 语义核对(输出侧定位):基线 src/locale.rs 共 19 条 debug_assert!(注:实现方宣称 16 条,实为 19),全部位于 decode_to_visible_text 扫描循环之后、return out 之前的单一输出侧块内;扫描臂(guard 消费臂、E400 臂、E000+E0xx raw-byte 臂、_ fallthrough)与基线逐字节一致,无任何扫描侧断言被误删。
  2. 每码点合法用户数据通路成立:CTLESC 0x11 等 C0 经 E000+E0xx raw-byte 对入站、解码还原为字面 char(x=$'\x11' 实测);guards U+E314-E317 与 ASSIGN 哨兵 U+E301-E30C/WS tag 均在 MARKER_ZONE(E000..E401)内,入站经 push_literal_char E400 转义(user-typed PUA codepoints collide with the marker registry: ANSI-C E401 is silently swallowed (data loss); E301/E314 miscount as length 2 #735)、E400 臂原样还原(x=$'\uE314Z' 实测);__RUBASH_HD1__/__RUBASH_CSB1_ 为可键入 ASCII,_ 探针只匹配 __RUBASH_CA1__,其余 verbatim 落盘。
  3. markers.rs 表格新行:Display value / xtrace rendering 两行引用的符号全部属实(builtins/declare/storage.rs 的 display_text/quote_array_element_value;prompt_expansion.rs xtrace 臂实调 decode_to_visible_text);golden rule 修订为 marker-free 输入 + tests/marker_leak_golden.rs,与模块纪律节自洽。
  4. 根因复现(base debug 构建):四个 oracle 全部在基线 debug 二进制上 panic(rc=1):QUOTED_HEREDOC_MARKER leaked(locale.rs:633)、COMSUB_PAYLOAD_PREFIX leaked(:637)、PARAM_WORD_BACKSLASH_GUARD leaked(:558)、CTLESC leaked(:629)——两个宣称位点 + C0 族全部证实。
  5. 零非 debug 变化复验:4 个代表性 oracle(HD1 declare -p / CSB1 declare -p / U+E314 xtrace / 0x11 xtrace),修复树 debug 输出 vs 基线(992d5c5e)release 输出 stdout+stderr 逐字节一致(cmp 全 SAME)。
  6. 回归:修复树上新回归 8/8、decode_to_visible_text 7/7(其中新增 2 例,注:宣称 3 例)、marker_leak_golden 8/8 全绿;xtrace_carries_no_markers 在 base 树实测 失败(spawn 的 debug 壳 panic)→ 修复树 转绿,转换证实。全量双向对比(--no-fail-fast -- --test-threads=1 串行,两树各一遍):套件 304→305(+1 即新回归套件),套件限定失败名 diff:base 独有仅 xtrace_carries_no_markers,fix 侧零新失败。cargo fmt --check 干净。
  7. CI 硬 gate:新步骤位于 rust(ubuntu)job 内、--lib 之后,无 continue-on-error(相邻 cli_tests lane 才有)→ 失败即红;.config/nextest.toml 的 ci profile 只设超时,无 release 覆盖 → nextest 以 dev profile 构建 CARGO_BIN_EXE_rubash,壳内 debug_assert 处于武装状态,gate 真实有效。(本机无 cargo-nextest,行为复验用 cargo test 跑同一批测试二进制完成;gate 命令为静态核对。)
  8. 夹带/GPL:单父单提交;diff 恰为承诺 5 文件(ci.yml / markers.rs / locale.rs / 两个测试文件);GPL/FSF/版权文本零命中;worktree 干净。

NIT(非阻塞)

  1. 自引入的陈旧注释:src/locale.rs 约 452-467 行 declare -A name=(...) through the line-editor path panics in debug builds: COMPOUND_ASSIGNMENT_MARKER debug_assert (locale.rs) #802 白名单注释仍写 heredoc/comsub 载体 "keeps its never-seen golden assertion below"——其下方的 golden assertion 恰被本 PR 删除,注释现为假。建议顺手改成指向 tests/marker_leak_golden.rs。
  2. 陈旧交叉引用(既有,非本 PR 引入):src/executor/pipeline_exec.rs:3835-3838(niubash#383)引用 "debug_assert!(!contains(CTLESC)) postcondition (locale.rs:545)"——断言已不存在;不用的设计理由(内部文本不走该解码器,防静默误计数)仍成立。本 PR 不动该文件属正确裁剪,建议 follow-up 修注释。
  3. 审计中发现的既有非 debug 数据融合(明确 out-of-scope,建议立 issue):patsub 替换文本中用户 PUA 未走 E400 转义、与 PATSUB 标记碰撞——base/fix release 同样复现:v=abc; r="${v/b/$'\uE312x'}" 得 a&xc(U+E312 被当 PATSUB_QUOTED_AMP 渲染成 &,GNU 打印原字符);U+E310/E311 则被静默丢弃。与测试文件里 CSB1 printf 注记同类。expand_braced_replacement.rs:325-337 的 4 条 PATSUB 断言本身是健全的(四码点均被扫描臂在途消费,裸码点到不了输出),不属 marker debug_assert family: user-literal text panics debug builds at two more decode boundaries (HD1 in declare -p; PARAM_WORD_BACKSLASH_GUARD in xtrace) #824 panic 族——已实测确认。
  4. CHANGELOG 无条目——同族先例(declare -A name=(...) through the line-editor path panics in debug builds: COMPOUND_ASSIGNMENT_MARKER debug_assert (locale.rs) #802/user-typed PUA codepoints collide with the marker registry: ANSI-C E401 is silently swallowed (data loss); E301/E314 miscount as length 2 #735)亦无,按现状接受;维护者如需可补 Unreleased/修复 行。

红线核查:评审全程未杀任何进程、未触碰 rubash-wt-830 / rubash-wt-824 / 824-base / 主检出。

…aims the removed golden assertion (drop output-side asserts per #824)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant