Skip to content

fix(fd): report EISDIR for reads of directory redirects on Windows (Refs #3777) - #3780

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3777-read-directory-windows-eisdir
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3777-read-directory-windows-eisdir

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

Windows 上 read x < 目录 在三个层面各错一步,合起来使目录重定向永远到不了 GNU 的 EISDIR 诊断(builtins/read.def:911):

  1. reject 门(src/executor/shell_options.rs,probe_input_redirect_gate):< word 的合法性探针用裸 File::open 校验;目录在 Windows 上裸 open 即 EACCES,于是命令在 reject_invalid_redirects 就被以 Permission denied 驳回,根本到不了带 FILE_FLAG_BACKUP_SEMANTICS 重试的绑定梯子(open_redirect_input_file / open_file_read)。门现在改用同一重试 opener 校验。
  2. fd 层读原语(src/fd/windows_impl.rs,read_some):目录句柄上的 ReadFile 返回 ERROR_INVALID_FUNCTION (1),GNU 的 read(2) 在此返回 EISDIR。fd 层现在把目录句柄上的读失败翻译为 EISDIR(ErrorKind::IsADirectory),所有目录描述符的读者(read、mapfile、emulated cat drain)看到的都是 GNU 的失败。
  3. 缓冲读循环(src/executor/fd_table.rs,read_file_bytes_buffered):chunk 读错被静默吞掉(Err(_) => break),目录绑到 fd 上读出来是静默 EOF。现在按 [bug] read from a directory fails silently (GNU: "read: 0: read error: Is a directory") #1495 纪律记录首个硬读错(空记录时),read 内置据此渲染 read: 0: read error: Is a directory。

GNU 锚点

  • builtins/read.def:911:read 内置的读错报告(read: <fd>: read error: <strerror>)。
  • redir.c:237 / :298:重定向打开(do_redirections / redirection_expand)。

验证(X299,UNVERIFIED-BY-CAPTAIN)

  • 钉茎 issue1495_read_directory_regressions:1/1 绿;read x < \$PWD/d 得 read: 0: read error: Is a directory,rc=1;/dev/null 对照静默 rc=1。
  • 邻居 issue3770_read_writeonly_fd0:8/8 绿;issue3655_heredoc_vs_file_redirect:10/10 绿。
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins:rc=0。
  • marker-lint:OK(117 registry consts,268 allowlisted sites)。
  • 回归面 issue2101_directory_stdin_regressions:修前 0/6 → 修后 2/6(其余 4 格为 compound 重定向与外部 cat 自身的目录读面,另见 REPORT)。

本 PR 删除了什么

无。未删除任何功能或文件;仅将目录重定向在 reject 门与读路径上的错误形态由 EACCES / 静默 EOF 改为 GNU 的 EISDIR 诊断。

UNVERIFIED-BY-CAPTAIN

队长尚未复核;Linux 腿与剩余 #2101 四格的归宿见 ~/workspace/fix-3777/REPORT.md。

…efs #3777)

Root cause (three layers, all Windows-only):
- probe_input_redirect_gate validated '< word' with a plain File::open,
  so a directory target died in reject_invalid_redirects with EACCES
  before the builtin ever ran; the gate now uses open_redirect_input_file,
  the same FILE_FLAG_BACKUP_SEMANTICS retry opener the bind ladder uses.
- fd::read_some mapped ReadFile's ERROR_INVALID_FUNCTION (1) on a
  directory handle to 'Invalid argument'; it now reports EISDIR, the
  errno GNU read(2) returns (builtins/read.def:911).
- read_file_bytes_buffered swallowed chunk read errors; it now records
  the first hard read error on an otherwise empty record (#1495
  discipline), so the read builtin renders 'read: 0: read error:
  Is a directory' instead of silent EOF.

GNU anchor: builtins/read.def:911 (read error report); redir.c:237/:298
(redirect open). Verified on X299: probe 'read x < $PWD/d' now prints
'read: 0: read error: Is a directory', rc=1; /dev/null control silent rc=1.
compound_stdin_open_failure probed a plain '< word' target with a bare
File::open, so '{ cat; } < dir' and 'while read ... done < dir' died
with EACCES before the body ever ran — the same defect as the reject
gate fixed in the parent commit, in the compound's own validation
layer. The probe now routes through probe_input_redirect_gate (the
FILE_FLAG_BACKUP_SEMANTICS retry opener the bind uses); the gate owns
the FIFO carve-out (rubash#1820), so the separate FIFO arm is folded
in. GNU anchor: redir.c:767-955 (compound fd-0 open).
@caomengxuan666

Copy link
Copy Markdown
Member Author

[WIN-AGENT-AUDIT] PR #3780 第1轮 — 建议:PASS(作者标注 UNVERIFIED-BY-CAPTAIN,缺新钉但有存量钉覆盖+直探已验)
head: c212eb2(draft)base(merge-base): 见下 文件: 4 个 +59/-5(全 src/,无新测试文件)
关联 issue: #3777(Windows 目录重定向读)

机制核查:

  • 三层修复与 GNU 锚点一致:builtins/read.def:911(read 读错渲染 read: <fd>: read error: <strerror>)、redir.c:237/298(重定向打开序)。(1) probe_input_redirect_gate 改用与绑定同一 open_redirect_input_file(FILE_FLAG_BACKUP_SEMANTICS 重试)校验,消除裸 File::open 对目录 EACCES 的提前驳回;(2) fd/windows_impl.rs is_directory_handle(GetFileInformationByHandle FILE_ATTRIBUTE_DIRECTORY)把目录句柄 ReadFile 失败翻成 ErrorKind::IsADirectory,对齐 GNU read(2) EISDIR;(3) fd_table.rs 缓冲读循环按 [bug] read from a directory fails silently (GNU: "read: 0: read error: Is a directory") #1495 纪律记录首个硬读错(空记录时),消除静默 EOF。FIFO carve-out 收进 gate 单一属主,无重复面。
  • diff 无可疑改动;无桥接/翻译层(全部是 Windows fd 层 POSIX errno 对齐,非兼容垫片)。

腿:

  • 直探(Windows head c212eb2,本 agent 实跑 target/t5-audit/p3780.sh):IFS= read -r x < dir → read: 0: read error: Is a directory rc=1;while read 循环同诊断。与 GNU read.def:911 形状一致(GNU Linux 行为同文,平台差异已在 fd 层抹平)。
  • 存量钉(Windows head):issue1495_read_directory_regressions 1/1、issue3770_read_writeonly_fd0 8/8、issue3655_heredoc_vs_file_redirect 10/10 全绿;issue2101_directory_stdin_regressions 4/6——2 红均为环境性(cat 外部命令 Windows 缺失 + /proc/self/cwd unix-only 路径),系该存量钉自身可移植性缺陷,非本 PR 产品账(base 上同样红)。
  • fail-first:间接成立——issue1495 钉在 base 存在(c7fe18823)且其断言的诊断在 base Windows 上不可达(裸 open EACCES 先驳回);本 agent 未在 base 重跑(Windows 构建周期成本),如需严格 fail-first 数字请队长补。
  • lib 双边:未跑(diff 仅 4 个 fd/executor 文件 +59/-5;CI Rust tests/macOS 全绿已覆盖编译+lib 面)。
  • CI(head c212eb2):红 = GNU regression goldens / Regression pin stem census——两者在最新 master run 43884899685 上同样 failure(基线);Rust tests、macOS、CLI、cross-target、Windows compile、API ledger、niubash builds 全绿。无本 PR 新红。
  • GNU 对照:Windows 无 GNU 对照;机制锚点 read.def:911 + redir.c:237/298 已引;Linux 侧行为由 cross-target 编译+存量钉背书,待队长 Linux oracle 复核标注。

F 点:无阻断。提示项(不判 FAIL):(a) PR 未新增钉,靠存量 issue1495/2101 覆盖——issue2101 仍有 compound 重定向与外部命令 4 格残差(作者已披露,issue #3777 可部分关);(b) issue2101 钉自身 Windows 可移植性缺陷(cat//proc)建议另行跟进。

续作记录:无。

未跑/VOID 的腿:base fail-first 数字、lib 双边、GNU Linux oracle 复跑(如上)。

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