fix(libc): keep a drive-letter component of a guest path under its mount on Windows #6061
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6061"
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 wachi35676 on 2026-10-14T21:04:11Z.
What
On Windows, a guest path whose component looks like a drive letter escapes its mount.
Resolveappends guest components to the host root or to an alias directory withstd::filesystem::path::operator/. On Windows a component such asC:at the start of the appended part is parsed as a root name, so it replaces the host directory instead of being appended:mainresolves to/savedata0/C:/Windows/win.iniC:\Windows\win.ini<savedata dir>\C:\Windows\win.ini/app0/../C:/Windows/win.iniC:\Windows\win.ini<root>\C:\Windows\win.ini/C:/x<root>\x(component dropped)<root>\C:\x/savedata0/C:file<savedata dir>\file<savedata dir>\C:file(the NTFS alternate data streamfileofC; see below)On FreeBSD,
:is an ordinary file-name character, so these names belong under the mount. This is the same class of problem as the parent-traversal escape fixed in #3485.Guest paths are now split into component names and joined to the host directory as text (
SplitNames/Child), so a component is never reinterpreted as a root. The rest is unchanged:.and..handling, including the directory check before..ResolveHostPath/throughJoinNameseac8bfcfc(modulemode,<name>.guest.prxmatched in the same listing), which now runs on the component namesResolve(C:/...), which are still passed through as beforeOn NTFS a guest name containing
:is still not a plain file name:name:streamopens the alternate data stream ofname, as it already did onmain. A line indocs/dev/debt/libc.mdnow records it (creating/savedata0/C:filemakes an empty fileCwith streamfile,stat /savedata0/Creports a regular file,mkdirof a name containing:fails withEINVAL); each point was checked with a probe throughsceKernelOpen/sceKernelStat/sceKernelMkdir. Thanks to @screamm for pointing it out.Tested
Rebased on
main5050a23f3(aftereac8bfcfcandcee2006d1):guest_path_drive_componentaborts withmain'slibcand passes with this PR.guest_filesystem(#4681's and eac8bfcfc's checks).main's new path code: 87 plain paths and 376 module paths (<name>.guest.prxexact, other case, ambiguous, missing, a directory; under the root, aliases,..routes, with and without a trailing slash), each in plain and module mode from 4 working directories. Linux: identical (348/348 plain, 1504/1504 module per mode). Windows: every difference is a path with a drive-letter component (32 plain and 96 module per mode); nothing else differs, including ambiguity errors in a case-sensitive directory.Results below are from the first version (
13ffb79a4on799982fac):New test
guest_path_drive_component(core/libs/tests/GuestPathDriveComponent.cpp) covers drive components under an alias, after.., at the root and inside a directory.799982fac):main'sGeneral.cpp.guest_path*,guest_filesystem,guest_working_directory,guest_realpath,guest_directory*,guest_savedata_*,download_data_mount_*,guest_kernel_rename,guest_file*).guest_*,libc*,libkernel*andpathtests passed 412 of 413. The exception,guest_user_service, fails the same way onmain.guest_filesystem, where #4681's trailing-slash checks run.ResolveAliasthrough the new code, I dropped it before the alias lookup;guest_filesystemthen aborts.main's and this PR's path code side by side and resolved 87 guest paths in each of 4 working directories. The paths cover absolute and relative paths,.and.., repeated and trailing slashes, backslashes, alias prefixes (case variants and look-alikes such as/savedata0x), error cases, nativeC:/and UNC pass-through, and drive components.Overlap: #5280 and #5835 also edit
General.cppand conflict textually with this PR (each merges cleanly withmain): one small hunk inHostPathfor #5280 and two inResolvefor #5835. Whichever lands second needs a rebase. #4627 and #4927 merge cleanly with it.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 screamm on 2026-10-15T08:53:28Z.
Cross-check on Windows: #6061 head
13ffb79a4merged ontomaind92a8dad3; the merge is clean.Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release.
libsboth succeed, with no new warnings. The one warning inGeneral.cpp,u8pathdeprecated at line 445, ismain's line 410.--repeat until-fail:3:guest_path_drive_componentand 49 file-system tests pass 3/3, 150 of 150 runs:guest_path_case,guest_working_directory,guest_realpath,guest_filesystem,guest_posix_filesystem,guest_kernel_renameandguest_kernel_sys;guest_directory*,guest_file*,guest_savedata_*anddownload_data_mount_*tests.guest_path_drive_component_testsrun withmain'slibcaborts (FATAL: abort() (SIGABRT)).ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 815 tests, and 814 pass, including the 2 skipped.hardware_oracle_comparehit its own 20 s timeout, in the suite and again alone.Ran 8 tests in 36.066s,OK). It teststools/hw-oracle, which this PR does not touch.check_conventions.py --base origin/mainandgit diff --checkare clean.The exact case, through the guest API. A small probe calls
sceKernelOpen,sceKernelStatandsceKernelMkdir, with an alias/e2e-mountthat points to<dir>\Mounted:main/e2e-mount/C:/Windows/win.iniC:\Windows\win.ini0x80020002/e2e-mount/../C:/Windows/win.iniC:\Windows\win.ini0x80020002stat /e2e-mount/C:/Windows0x80020002/e2e-mount/C:/<dir>/Outside/written.txt0x80020002, nothing written/e2e-mount/C:inside.txtMounted\inside.txt(component dropped)0x80020002/e2e-mount/inside.txtSo on
maina guest can read and write anywhere on the host drive through any mount, and this PR keeps those paths under the mount.One related note, not introduced here. On NTFS a name with
:is not a plain file name. Creating/e2e-mount/C:filewith this PR makes a fileCwhose streamfileholds the data, andstat /e2e-mount/Cthen reports a file./e2e-mount/name:streambehaves the same way onmain.mkdir /e2e-mount/C:returns EINVAL; onmainit returns EEXIST, because it resolves to the mount itself. A debt line about:in guest names on Windows might be worth adding. The PR's table entry<savedata dir>\C:fileis such a stream.Titles. Catalog releases, relinked once with
main's relinker, so only the libraries differ. Each ran 60 s with the display on,app0/eboot.binstaged andHOMEunset.mainccleste loads its assets through
..under/app0, the path shape this PR rewrites:It reaches its title screen with both builds.
open/statlines are the same for each title on both builds.kodi.logerror lines on both builds, includingGetDirectory - Error getting /app0/addons, and the same 222 SQLite version-probecannot open filelines.O_DIRECTORYand gets the same result on both builds.Verdict: confirmed. The drive-letter escape is real on
main, for both reads and writes, and this PR closes it. The new test fails onmainand passes here, and there is no regression in the tests or the three file-I/O titles.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-15T12:13:13Z.
Thank you for the thorough cross-check, including the write case and the title runs.
The
:note is now indocs/dev/debt/libc.md. I checked each point with a probe throughsceKernelOpen/sceKernelWrite/sceKernelStat/sceKernelMkdiron a mount, listing the host streams withFindFirstStreamW:/mount/C:filemakes an emptyCwith a 4-byte stream:file, andstat /mount/Creports a regular file (0x80020002onmain, where the component is dropped andMounted\fileis written instead);name:streamgives the same result on both builds;mkdir /mount/C:returnsEINVALhere andEEXISTonmain, andmkdir dir:xreturnsEINVALon both.I also rebased onto
5050a23f3, pasteac8bfcfc, which reworkedResolveHostPathfor relinked modules. Its module lookup now runs on the component names unchanged. Comparingmain's and this branch's path code over 87 plain and 376 module paths from 4 working directories gives identical results on Linux; on Windows every difference has a drive-letter component. The PR description has the details. Windows 49/49 and Linux 40/40 path, file system and module tests pass.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:14:03Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL84core/libs/prx/libc/src/General.cppL114-116, L118-119Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/General.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/General.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:38:20Z.
Rebased onto current
main. The conflict was inResolvewith thearchivedparameter and theapp0.zardirectory check before..; I kept that check and applied it to the component-name version. Build and the 114 tests in scope pass here, apart from two unrelated ones (guest_syslog,guest_allocator_failures) that fail under load and pass on re-run.guest_path_drive_componentpasses on Linux without the change, as expected (the bug is Windows-only), so the Windows evidence is the author's and @screamm's runs; merging after the full Build's windows job is green.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-17T16:41:37Z.
Thanks for the rebase. Since then #5280 merged and added
ProvidedPathin front ofHostPath, which conflicted again, so I've rebased ontomain66702f1cf(78cabf5dc, on top of your resolution, theapp0.zarcheck before..unchanged).ProvidedPathnow takes the component names likeHostPath: the provider lookup usesTrimSlashes(JoinNames(names)), and the "already supplied" check callsResolveHostPath(state.root, names).HostPathasks it afterResolveAliasand beforeResolveHostPath, as onmain.guest_path_drive_component,guest_sandbox_certificates,guest_sandbox_certificate_trustandguest_sandbox_random_word.python tools/check_conventions.py --base origin/mainpasses.AI-assisted: yes (Claude Code); results above were run on this machine.