fix(libkernel): report ELOOP for a path below a Windows symlink loop #8655

Merged
cadenasynyster merged 1 commit from upstream-pr/8655 into main 2026-10-21 07:57:13 +00:00
cadenasynyster commented 2026-10-20 20:08:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-20T20:08:07Z.


What

On Windows, sceKernelOpen and POSIX open of a path below a symbolic link that points to itself (loop/inside, with loop -> loop) returned ENOTDIR (20). FreeBSD returns ELOOP (62). The native open fails with ENOENT or ENOTDIR there, and NotFoundError_nid_no_patch then reports ENOTDIR because the existing prefix loop is not a directory.

When the native open fails with ENOENT or ENOTDIR, OpenNative now runs the loop check that sceKernelStat already uses (NativeSymbolicLinkLoop, which tests for ERROR_CANT_RESOLVE_FILENAME) and returns ELOOP if it hits. The change is under _WIN32 and only runs on the failure path.

This is one row of #6983. It does not touch WindowsOpenError_nid_no_patch, so it does not overlap with #8640, which maps the open("loop") row there. The new checks sit in a different part of GuestFilesystem.cpp.

Tested

  • Windows 11 (NTFS, Developer Mode on), WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, base main 29e4c46b4.
  • Before: a probe printed ENOTDIR (0x80020014, POSIX errno 20) for open(loop/inside) on main. A direct CreateFileW on both loop and loop\inside fails with 1921 (ERROR_CANT_RESOLVE_FILENAME).
  • guest_filesystem has two new checks: sceKernelOpen of stat-loop/inside returns 0x8002003e, and POSIX open returns -1 with errno 62. With only the Open.cpp change removed, guest_filesystem aborts with exit code 0xc0000409; with it, it passes.
  • ctest -R "guest_filesystem|guest_path_name_length|file|stat|open|path": 75/75 passed.
  • python tools\check_conventions.py --base origin/main passes.
  • Not run: Linux and macOS (the change is Windows-only code), fopen of the same path, and the rename and unlink paths.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (one row of #6983)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4941783244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8655). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-20T20:08:07Z. --- ### What On Windows, `sceKernelOpen` and POSIX `open` of a path below a symbolic link that points to itself (`loop/inside`, with `loop -> loop`) returned ENOTDIR (20). FreeBSD returns ELOOP (62). The native open fails with ENOENT or ENOTDIR there, and `NotFoundError_nid_no_patch` then reports ENOTDIR because the existing prefix `loop` is not a directory. When the native open fails with ENOENT or ENOTDIR, `OpenNative` now runs the loop check that `sceKernelStat` already uses (`NativeSymbolicLinkLoop`, which tests for `ERROR_CANT_RESOLVE_FILENAME`) and returns ELOOP if it hits. The change is under `_WIN32` and only runs on the failure path. This is one row of #6983. It does not touch `WindowsOpenError_nid_no_patch`, so it does not overlap with #8640, which maps the `open("loop")` row there. The new checks sit in a different part of `GuestFilesystem.cpp`. ### Tested - Windows 11 (NTFS, Developer Mode on), WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, base main `29e4c46b4`. - Before: a probe printed ENOTDIR (`0x80020014`, POSIX errno 20) for `open(loop/inside)` on main. A direct `CreateFileW` on both `loop` and `loop\inside` fails with 1921 (`ERROR_CANT_RESOLVE_FILENAME`). - `guest_filesystem` has two new checks: `sceKernelOpen` of `stat-loop/inside` returns `0x8002003e`, and POSIX `open` returns -1 with errno 62. With only the `Open.cpp` change removed, `guest_filesystem` aborts with exit code 0xc0000409; with it, it passes. - `ctest -R "guest_filesystem|guest_path_name_length|file|stat|open|path"`: 75/75 passed. - `python tools\check_conventions.py --base origin/main` passes. - Not run: Linux and macOS (the change is Windows-only code), `fopen` of the same path, and the rename and unlink paths. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none (one row of #6983) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-20 20:10:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:10:54Z.

Review: APPROVED


Reviewed the diff and the Windows validation report. The loop check runs only after a failed open with ENOENT or ENOTDIR, uses the existing NativeMetadataPath handling for long paths, and returns the guest ELOOP code before NotFoundError_nid_no_patch can turn the self-loop prefix into ENOTDIR. The two regressions cover the sceKernelOpen result and POSIX errno. The Windows 11 run reports the focused test set passing 75/75. I found no blocking code issue. Hosted Linux and Windows build jobs are skipped, so that manual Windows run is the runtime evidence for this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5591069617 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8655#pullrequestreview-5591069617). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T20:10:54Z. **Review:** APPROVED --- Reviewed the diff and the Windows validation report. The loop check runs only after a failed open with ENOENT or ENOTDIR, uses the existing `NativeMetadataPath` handling for long paths, and returns the guest ELOOP code before `NotFoundError_nid_no_patch` can turn the self-loop prefix into ENOTDIR. The two regressions cover the `sceKernelOpen` result and POSIX errno. The Windows 11 run reports the focused test set passing 75/75. I found no blocking code issue. Hosted Linux and Windows build jobs are skipped, so that manual Windows run is the runtime evidence for this change.
github-actions[bot] commented 2026-10-20 20:26:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T20:26:19Z.


Some 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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/File/src/Open.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
PR 6936 core/libs/prx/libkernel/File/src/Open.cpp
PR 7121 core/libs/prx/libkernel/File/src/Open.cpp
PR 7201 core/libs/prx/libkernel/File/src/Open.cpp
PR 8520 core/libs/prx/libkernel/File/src/Open.cpp
PR 8550 core/libs/tests/GuestFilesystem.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300725178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8655#issuecomment-6300725178). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T20:26:19Z. --- <!-- pr-overlap --> Some 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. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libkernel/File/src/Open.cpp` | | [PR 8550](https://www.github.com/boykopovar/AnyPS5/pull/8550) | `core/libs/tests/GuestFilesystem.cpp` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8655
No description provided.