Skip to content

mark_literal_ifs_chars 对未闭合 $(…/反引号 词的 raw-skip 哨兵越界:copy 循环 index == len 时 panic 整个 shell(niu 1.4.1 journey P7 崩溃面) #875

Closed

Description

@caomengxuan666

现场证据(release run 39233051251,tag v1.4.1,rubash pin 45f537e)

journey 的 P4-S4-terminal / P7-session-open / P7-S3-corrupt-boot 全部在 boot 时崩溃:

thread 'niu-main' (6388) panicked at D:\a\niubash\rubash\src\executor\command_prepare.rs:3919:46:
index out of bounds: the len is 132 but the index is 132

backtrace(release 内联后符号有漂移,file:line 可信)apply_completion_actions ← VariableStore::get ← execute_command。每次会话 boot 崩 → pty closed → journey P3/P4/P7/P8 大面积红。

根因(45f537ea 与 master 均在,#743 followup 漏掉了两个分支)

mark_literal_ifs_chars(command_prepare.rs:3827)用 skip_raw_* 帮手的返回值做排他上界拷贝词体:

  • :3917 $(...) 分支:let end = skip_raw_command_substitution(&chars, index + 1); while index < end { chars[index] }
  • :3947 反引号分支:let end = skip_raw_backtick(&chars, index); while index < end { chars[index] }

而帮手在未闭合 span 尾部是反斜杠时返回越界哨兵('\\' => index += 2 的逃逸跳一步跨过缓冲区,skip_raw_quote/skip_raw_backtick 都会返回 len+1 及以上)。${…} 分支在 #743 followup(注释 3871-3878,probe 2026-10-18)已 clamp:.min(chars.len())——但 $(…) 与反引号两个分支漏掉了。

触发链:主题脚本设 IFS + 词含未闭合 $(... 且尾随 \ → expand_command_word → mark_literal_ifs_chars → panic。

最小复现(本机已验证,45f537ea 红/补丁绿)

``\rust
mark_literal_ifs_chars(r#"$("a\"#, " \t\n");
// 未打补丁:panicked at command_prepare.rs:3919:46, the len is 5 but the index is 5
mark_literal_ifs_chars(r#"`a\"#, " \t\n");
// 未打补丁:panicked at command_prepare.rs:3949:34, the len is 3 but the index is 3


(真实案例 len=132:主题脚本里一行 132 字符的词。)

## 修复(分支 fix/873-raw-skip-sentinel-clamp,PR 随后)

两个 copy 循环同样 `.min(chars.len())` clamp——未闭合体按原样逐字拷贝,与 braced 分支 #743 followup 的契约一致。回归测试 3 个($() 红、反引号红、普通词 byte-identical),全套 lib 测试 707 通过。

Activity

  1. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions