Skip to content

fix(find): probe roots with extended paths; stop false ENOENT and long-path recursion crash - #1285

Merged
caomengxuan666 merged 2 commits into
unixwin:mainfrom
Catapult291:fix/find-long-path-native-probe
Oct 23, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:mainfrom
Catapult291:fix/find-long-path-native-probe

Conversation

@Catapult291

Copy link
Copy Markdown
Collaborator

Summary

find treated existing directories past MAX_PATH as missing and could hard-crash (STATUS_STACK_BUFFER_OVERRUN / 0xC0000409) when recursion walked into long child paths.

Root cause (local diagnosis on WinuxCmd 1.1.20 + niubash 1.4.4):

  1. Start-root probes in scan_one_root / -delete / -depth used std::filesystem::exists without the \\?\ prefix → ERROR_PATH_NOT_FOUND on long paths.
  2. Error text was hard-coded to No such file or directory for every failure mode.
  3. recursive_directory_iterator also walked unprefixed paths → stack overrun on deep/long subtrees.

Changes

  • Probe existence via native_path::exists_w (attributes + extended path).
  • Walk with extended paths (to_io_path); map back with logical_from_io so find . still prints relative paths and -path works.
  • Map Win32 errors through win32_posix_error_text; sharing/lock violations become Permission denied; true missing stays ENOENT.
  • Do not silence iterator failures.
  • Unit tests: long root is not reported missing; missing root still ENOENT.

Refs #1283

Test plan (Windows, installed 1.1.20 + this patch)

Probe Before After
find <dir-len≈360> -maxdepth 0 -type d ENOENT, rc=1 rc=0
find <long> -name f.txt fail / incomplete lists files
find <short-root> -type f descending long child crash 3221226505 rc=0
find <missing> -maxdepth 0 ENOENT still ENOENT
find . -maxdepth 0 prints . unchanged

Related shell-side record: niubash defect log D9 (2026-10-23).

Catapult291 and others added 2 commits October 23, 2026 20:20
std::filesystem::exists without \\?\ false-ENOENTs roots past
MAX_PATH and recursive_directory_iterator overflow-crashes when
descending into them. Probe via native_path::exists_w, walk with
\\?\ and map back for display, and stop hardcoding ENOENT for
sharing/lock violations.
wpath() already returns std::wstring; the chained call only exists on
std::filesystem::path, so MSVC rejects the translation unit. Fixes the
x64 build-windows job.
@caomengxuan666
caomengxuan666 merged commit 665d3e8 into unixwin:main Oct 23, 2026
8 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for this one — and for doing the root-cause work before opening the PR. The missing \\\\?\\\\ prefix on the start-root probes is exactly the sort of thing that passes every normal test and then blows up on the one machine with long paths, and the 0xC0000409 crash report made it easy to take seriously. Merged with a two-line touch-up on the new test (wpath() already returns a wstring, so the chained .wstring() didn't compile under MSVC) — otherwise as-is. It'll ship in the next release. If you find more of these, we'd take them.

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.

2 participants