Skip to content

[bug] grep -r 递归进入 pnpm 符号链接树(.pnpm 交叉链接)栈溢出崩溃 0xC0000409,输出 0 行且 stderr 为空,与"无匹配"同形 #1135

Closed

Description

@lanbg1996

环境

  • WinuxCmd 1.0.8 与 1.1.3 均复现(本机 1.0.8 实测;另下载官方 v1.1.3 独立实测同样崩溃)
  • Niubash 1.2.0(rubash git 8ed028eb1138),Windows 10.0.19045 x64

复现

在任意使用 pnpm 的项目根目录执行(node_modules 为 pnpm 符号链接布局):

cd <项目根>            # 含 node_modules/.pnpm 交叉符号链接
winuxcmd grep -rn pattern .

实际输出:0 行,stderr 为空,退出码 -1073740791(0xC0000409,STATUS_STACK_BUFFER_OVERRUN,进程级 abort)。

GNU grep / ripgrep 同命令正常命中。

触发边界(实测二分)

目标 结果
.(项目根,含 node_modules) 崩溃
node_modules(整体) 崩溃
node_modules/.pnpm(整体) 崩溃
node_modules/ant-design-vue(单个符号链接) 正常
node_modules/.pnpm/@[email protected]/node_modules(单个包目录) 正常
--exclude-dir=node_modules . 正常(214 命中)

即:单个符号链接、单层目录均可正常遍历;一旦递归进入 .pnpm 的多包交叉符号链接树(如 ant-design-vue -> .pnpm/[email protected][email protected]_.../node_modules/ant-design-vue,包内再指向其它 .pnpm/... 包)即栈溢出崩溃。简单自环(a/self -> a)不触发,需要这种多级交叉结构。

为什么严重

rc=0xC0000409 且 stdout/stderr 全空,与"没有匹配"完全同形:grep ... 2>/dev/null | wc -l 会把它当成 0 命中的正常结果。对 AI agent 的 shell 使用而言,等于静默给出错误结论(实测中我因此把"某目录不含某字段"的假结论写进了交付报告,靠人工复核才发现)。

期望

参照 #1064(cp -r 遇 junction 循环爆 31 层)的同族修复:

  • 递归遍历应对符号链接循环有防护(跳过/去重已访问的真实路径),至少不应进程级崩溃;
  • 崩溃或错误时给出非零退出码之外的诊断信息(stderr 文本),不能与"无匹配"同形。

Activity

  1. added a commit that references this issue on Sep 29, 2026
  2. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    Member

    修复在 PR #1136(已合并,将随下个 tag 发布)。根因:pnpm 的 node_modules 用的是 NTFS junction,std::filesystem 不把它当符号链接,follow_directory_symlink 开关无效,recursive_directory_iterator 在交叉树里无限递归到栈溢出。现已改为显式栈遍历:-r 直接跳过 reparse 目录(GNU 语义),-R 跟随但按真实路径去重并在遇环时输出 stderr 警告,不再与无匹配同形。你报的复现场景实测:命中正常、退出码 0。感谢这份二分报告,边界条件写得非常清楚。

  3. added
    bug
    on Oct 17, 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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions