fix(libc): fail with ENOTDIR for a file named with a trailing slash on Windows #9109
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9109"
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 Retr0G28 on 2026-10-21T12:33:03Z.
What
On Windows a path that names a regular file with a trailing slash (
file/) did not fail withENOTDIR. Under a mount alias such as/savedata0,ResolveAliasdropped the slash on Windows only, sounlink,remove,rename,openandsceKernelUnlinkacted on the file. Outside an alias the slash reached the host, but Windows does not reportENOTDIRforfile\either:_wunlinkfails withERROR_DIRECTORY(267), which came back to the guest asEINVAL. FreeBSD 11.4'slookup()(sys/kern/vfs_lookup.c) fails withENOTDIRwhen a path with a trailing slash ends at something that is not a directory (TRAILINGSLASHcheck).#4681 fixed this for Linux and macOS and left Windows out, because Windows handles trailing separators differently (#4513) and it could not be tested there. This PR:
Resolveincore/libs/prx/libc/src/General.cppthrowENOTDIRwhen the guest path ends in a slash and the host target exists and is not a directory (following symbolic links, aslookup()does with a trailing slash). Every libc and libkernel path call that resolves a guest path goes through it, so this coversopen,sceKernelOpen,unlink,remove,sceKernelUnlink,rename(source and target),stat,access,chmod,mkdirandrmdir, under an alias or not. A directory with a trailing slash and a missing name with one are unchanged.#ifndef _WIN32inResolveAlias, so an alias keeps the trailing slash on every host, as paths outside an alias already do.The
Trailing slash on a mount aliasentry is cut fromdocs/dev/debt/libc.md. One related gap remains and is recorded indocs/dev/debt/libkernel.md:openwithO_CREATon a missingnew/fails withEINVALon Windows (and the host'sEISDIRon Linux), where FreeBSD fails withENOENT. That needs the operation inopenand is a separate change.Test changes in
guest_filesystem(TestParentTraversal):parent-test-mountalias now runs on every host, not only on Linux and macOS.renameonto an existingfile/,stat,access,chmod,mkdir,rmdirandsceKernelOpen(O_CREAT)onfile/(allENOTDIR),unlinkoffile/outside the alias, andsceKernelOpen("Existing/", O_DIRECTORY).Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, onmaind099bc6cd; after rebasing ontomain2f161d4f3(no changes to libc or libkernel),guest_filesystem,guest_posix_filesystemandguest_kernel_syswere run again and pass. Rebased again ontomain9d6adeb550after #8797 merged: its dot-component checks are kept and the#ifndef _WIN32below them is removed;guest_filesystemandfile_streamspass.General.cppfrommain, new test kept),guest_filesystemfails at the first trailing-slash check:Filesystem check failed at line 252,unlink("/parent-test-mount/slash-unlink/")does not return -1 with errno 20. With only the#ifndef _WIN32removed it fails at the same line with guest errno 22 (Win32 error 267).guest_filesystempasses.guest_filesystem,guest_posix_filesystem,guest_directory,guest_directory_rewind,guest_directory_entries,guest_directory_close,guest_directory_buffer,file_streams,file_position,file_identity,guest_kernel_sys,guest_kernel_rename,guest_rename_dot,guest_realpath,guest_working_directory,guest_path_case,guest_path_drive_component,guest_path_name_length,guest_statvfs,guest_fstatvfs,guest_fstatfs,guest_fdopendir,guest_fiopen,guest_fopen_long_host_path,guest_shm_open,guest_savedata_mount_status,savedata_replace_file_failure,guest_system_service_path_boundary,guest_app_archive_present,guest_app_archive_absent,guest_app_archive_damaged,guest_app_archive_invalid,guest_kernel_app_archive_archive,guest_kernel_app_archive_plain,guest_kernel_app_archive_mmap.python tools/check_conventions.py --base origin/mainreports no errors.guest_filesystempasses 3 of 3, and fails 3 of 3 withmain'sGeneral.cpp(comment below).ENOTDIRforfile/, so the new check returns the same error earlier; Linux CI runs the sameguest_filesystemblock it ran before, plus the new lines.Overlap:
tools/pr_overlap.pyreports three PRs sharing lines. #8797 (now merged) added dot-component checks toTestParentTraversalincore/libs/tests/GuestFilesystem.cppright above the#ifndef _WIN32this PR removes, and this PR is rebased onto it; it makesunlinkandrmdirofdir/.anddir/..fail withEINVALand trims the slash before resolving the parent, so it does not implement the same thing and does not change what this check sees. #8544 touches neighbouring lines ofdocs/dev/debt/libkernel.mdonly. #8546 removes thetznameentry directly above thedocs/dev/debt/libc.mdentry this PR removes, so whichever of the two merges second needs a one-line rebase. #8550 also editscore/libs/tests/GuestFilesystem.cpp, in thefopendirectory checks inmain, away from these lines. The script could not compare some PRs that conflict withmain; of those touchingGeneral.cpp(#4627, #5021, #6544, #6879, #7201), none changes trailing-slash handling.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)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:44:05Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyguest_filesystem_tests;ctest -N -R guest_filesystemlists exactly one test.PR head tested:
c44e884cab97d7591827b62039d68b4bc50e38a9.Results (3 runs each):
guest_filesystempasses 3/3.core/libs/prx/libc/src/General.cppwith the version from the PR's merge base (2f161d4f33), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.GPU: the run output has no
Selected GPUline; no GPU claim is made.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:50:05Z.
Hi @Retr0G28, the same note as on #8544: my #9557 and #9561 edit the
fcntlrow ofdocs/dev/debt/libkernel.mdthat this PR also changes, and they conflict in that file only. Proposal: no dependency either way; whichever merges second keeps every sentence. OK with you?AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-22T15:27:50Z.
@DavidSamir Agreed, no dependency either way. This PR doesn't change the
fcntlrow itself: it adds the "Creating through a trailing slash" entry directly above it indocs/dev/debt/libkernel.md, so the conflict with #9557 and #9561 is only the two adjacent edits. Whoever merges second keeps both.