Skip to content

path: canonicalize Windows namespaced paths - #62639

Closed
jazelly wants to merge 1 commit into
nodejs:mainfrom
jazelly:fix-62446
Closed

path: canonicalize Windows namespaced paths#62639
jazelly wants to merge 1 commit into
nodejs:mainfrom
jazelly:fix-62446

Conversation

@jazelly

@jazelly jazelly commented Apr 8, 2026

Copy link
Copy Markdown
Member

Canonicalize valid Windows namespaced drive and UNC filesystem paths by stripping the prefix in these 2 kinds

\\?\C:\foo
\\?\UNC\server\share\foo

This is safe for ToNamespacedPath() because it resolves to the regular drive or UNC spelling before adding the namespace prefix back for Windows filesystem calls.

Fixes: #62446

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Apr 8, 2026
@jazelly jazelly added fs Issues and PRs related to file-system APIs and the fs module. path Issues and PRs related to the path subsystem. labels Apr 8, 2026
@StefanStojanovic StefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Apr 9, 2026
@jazelly
jazelly force-pushed the fix-62446 branch 2 times, most recently from 8a63ce2 to 9c279df Compare April 29, 2026 22:48
@johncrim

johncrim commented Jun 9, 2026

Copy link
Copy Markdown

Related:
#60435
#61165

Another PR which provides a simpler fix for those issues. Ideally this PR should handle the toRealPath() exception too.

@jazelly
jazelly marked this pull request as ready for review June 9, 2026 06:07
@jazelly jazelly added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Jun 9, 2026
@jazelly
jazelly force-pushed the fix-62446 branch 2 times, most recently from 6468284 to d0dc6a0 Compare June 9, 2026 06:17
@jazelly

jazelly commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@johncrim I think that's two different things, although very close, to fix. This PR aims to fix the extended path on windows.

@jazelly jazelly added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Jun 9, 2026
@jazelly jazelly changed the title path: handle extended-length windows entry paths path: canonicalize Windows namespaced paths Jun 9, 2026
Canonicalize Windows namespaced paths at internal filesystem identity
boundaries. Valid namespaced drive and UNC paths identify the same
filesystem objects as their non-namespaced spelling, so internal cache,
permission, and module lookups should compare the canonical identity
rather than the user-provided spelling.

Only the two known filesystem-equivalent namespace forms are rewritten:
\\?\C:\... and \\?\UNC\server\share\.... Other namespaced
forms are preserved because they may refer to device or drive-relative
semantics that are not equivalent to ordinary drive or UNC paths.

Signed-off-by: jazelly <xzha4350@gmail.com>
@jazelly

jazelly commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

After second thoughts and understanding to other mentioned issues, I think we should take care of them at the js layer to be safer. Closing this

@jazelly jazelly closed this Jun 9, 2026
stefanxfy pushed a commit to stefanxfy/ielts-copilot that referenced this pull request Sep 7, 2026
根因(github.com/nodejs/node/issues/61165):
  Tauri v2 Windows 上 resource_dir() 返回带 \\?\ 前缀的 DOS device path
  (\\?\C:\Users\admin\AppData\Local\IELTS Copilot)。
  Node v22 的 realpathSync 在解析该前缀时把盘符截短成 'C:',
  然后 lstat 'C:' 失败 → EISDIR 错。
  Node v20 能处理 \?\ 路径,v22/v24 不再支持。

postbuild 修复(b2c3a00)已清空 server.js 中 nextConfig 嵌入的 CI 路径,
但还不足以解决 Node 启动入口 realpath 时的 DOS device path 处理。

修法:新增 strip_verbatim_prefix() 函数,在 bootstrap 拿到 resource_dir
后立即剥前缀。所有 spawn 用到的路径(资源/cwd/env)都从已 strip 的
resource_dir 派生,Node 不会看到带前缀的路径。

参考:
  github.com/nodejs/node/issues/61165
  github.com/nodejs/node/pull/62639 (修复 PR 但 HTTP 行为变更混进)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. path Issues and PRs related to the path subsystem. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node cannot handle extended windows paths

4 participants