fix(libc): change into a directory whose host path exceeds MAX_PATH on Windows #24114
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24114"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by XFlawless1 on 2026-11-20T06:37:52Z.
What
On Windows,
chdirandfchdirinto a directory whose host path isMAX_PATHor longer fail withENOENT, andgetcwdfails the same way once the current directory is that long.SetWorkingDirectoryvalidates the target withstd::filesystem::canonical, and MinGW's libstdc++ cannot do that for such a path: the plain form fails, the\\?\form fails too, andequivalentcompares by drive letter. A deeply nested directory, or one reached through a substituted drive, junction or symlink whose target is long, hits it;fchdiralways gets the resolved target from the descriptor.canonicalfails on a path thatNativeVerbatimPath_nid_no_patchsays needs the\\?\prefix,SetWorkingDirectoryopens the target and the root through Win32 at their extended-length paths, takes both final paths fromGetFinalPathNameByHandleW(prefix removed, because libstdc++ does not parse\\?\C:\paths into a root name), and stores the root-relative result incurrentas the existing code does. A target that is not a directory returnsENOTDIR; any other failure returns the errno the existing path returned. Paths that do not need the prefix take the existing path unchanged.getcwdchecks the current directory at its extended-length path.GuestWorkingDirectory(Windows) changes into a directory whose path exceedsMAX_PATHand checksgetcwd, relative resolution,ENOTDIRandENOENT.GuestKernelSys(Windows) does the same throughfchdiron a directory descriptor, before the existing directory tests.#22932 changes the same lines for the macOS
PATH_MAXcase; itsFitsHostPathreturns true on Windows, so the two do not overlap in behaviour. Whichever merges second keeps both: #22932'sCanonicalHostPath/ShortHostPathcalls, with this PR's fallback on thecanonicalerror andIsDirectoryaroundShortHostPathingetcwd. I will rebase this one if #22932 lands first.Not in this PR:
mkdiratand the other*atexports join the descriptor's plain path and call Win32 with it, so they still fail for a long directory descriptor (guest_kernel_sysstops there when its working directory resolves to a long path).Tested
Windows 11, MinGW-w64 GCC (WinLibs UCRT), Ninja, Release, AMD Ryzen 7 9800X3D. The build directory is reached through a
substdrive whose target is over 260 characters, which is how this was found: onmain,guest_kernel_sysfailed atfchdirfrom the build directory and passed from a short one.General.cppreverted and the new tests kept, run from a short directory:GuestKernelSysfails at the newfchdircheck with errno 2, andGuestWorkingDirectoryaborts in the new case. With the change both pass from the short directory, andguest_working_directorypasses from the long build directory too.ctest -j16(6470 tests) onmainand with the change: no test goes from passing to failing exceptagc_driver, which timed out at 120 s under the parallel load and passes alone in 20 s, as onmain(21 s); see #22565.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T06:41:05Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0985414896:tools/check_conventions.pypassed.guest_kernel_sys_tests,guest_working_directory_testsbuilt cleanly.guest_kernel_sys,guest_working_directory):core/libs/prx/libc/src/General.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:53:00Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
0985414896afce58e586df8db999b305cf3ec6fffrom the prepared diff and targeted source excerpts. No build or tests were run.Results
Findings
Blocking
None in the code reviewed.
Non-blocking
None.
Not verified
Read
review/description.md,review/commits.md,review/manifest.json,review/diff.patch, and targeted excerpts ofcore/libs/prx/libc/src/General.cppandcore/libs/tests/GuestKernelSys.cpp. The full text of all three changed files is included inreview/files/, but the complete files were not read; in particular,core/libs/tests/GuestWorkingDirectory.cppwas not read. No tests, build, Windows host behavior, or author-reported test output were independently verified. No files were excluded according to the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T09:24:37Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
281cb49fc5:tools/check_conventions.pypassed.guest_kernel_sys_tests,guest_working_directory_testsbuilt cleanly.guest_kernel_sys,guest_working_directory):core/libs/prx/libc/src/General.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:35:38Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the long-path buffer sizing so
getcwdand directory changes work when the resolved final host path exceedsMAX_PATH.What I ran
Reviewed head
281cb49fc53ea900013c6f5547fb2f25b65da89f; no build or tests were run. The review bundle and repository source were read throughrepo_read.py.Results
Findings
Blocking
core/libs/prx/libc/src/General.cpp:560: WhenGetFinalPathNameByHandleWfirst reports a required length at leastMAX_PATH, the buffer is resized to exactly that value and passed back to the API. The API requires space for the terminating null; with an exactly sized buffer, the second call returns a value at least as large as the buffer, and the subsequent check rejects it. Thus long final paths cannot be obtained by this fallback, so the primary behavior under review fails for the paths it is meant to handle. Allocate space for the terminator before retrying, then trim to the returned path length.Non-blocking
None.
Sources
General.cppat the cited line.NativeVerbatimPath_nid_no_patchprovides the extended-length path used for the Win32 handle query.fchdir_nid_postfixpasses the descriptor path intoSetWorkingDirectory_nid_no_patch.Not verified
files.jsonwas not exposed in the review folder. The manifest and listing show all three changed files included; all their changed lines were read. No changed file was excluded.To get this to a good state
FinalDirectoryPath; rerun the Windows long-path checks and relevant test suite on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:08:59Z.
Review: APPROVED
Reviewed — looks good
The change adds Windows long-path handling for working-directory updates and
getcwd; no verified blocking defect was found in the inspected code.What I ran
Reviewed head
82b138aa1dedd99bf0d9da9a2ee011b4c201a36eusing the prepared diff andrepo_read.py. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No executable checks were run. The author-reported Windows 11 test results were not independently verified. The three changed files listed as reviewed in
manifest.jsonwere read; no changed files were excluded.To get this to a good state
Nothing is required.