fix(libc): fail an oversized guest path name with ENAMETOOLONG #8164

Merged
xXPBSXx merged 3 commits from upstream-pr/8164 into main 2026-10-20 02:22:03 +00:00
xXPBSXx commented 2026-10-20 01:03:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T01:03:17Z.


What

stat, open, mkdir, unlink, rmdir, rename, access and the other calls that resolve a guest path answer ENOENT (and rename EIO) for a path name that FreeBSD refuses as too long, because the resolved host path does not exist. FreeBSD 11.4's namei (vfs_lookup.c) fails a path component above NAME_MAX (255 bytes) and a path of MAXPATHLEN (1024 bytes including the terminating NUL) with ENAMETOOLONG (63).

Resolve() in General.cpp (behind ResolvePath_nid_no_patch) now checks the whole path (1024 bytes) on the guest string before resolving it, and a component above 255 bytes only when every component before it exists and is a directory (namei resolves in order, so a missing directory earlier in the path still answers ENOENT). Both throw a filesystem_error with filename_too_long; FilesystemError already maps that to 63 and ResolvePathError_nid_no_patch, which the kernel calls use, turns it into the errno. A name of exactly 255 bytes is not affected.

chflags resolved its path with the throwing form and without a try block, so a long name would have ended the title once this check exists. A second commit makes it use ResolvePathError_nid_no_patch like chmod; guest_path_name_length has a chflags case for it. The third commit adds a technical debt entry.

Limits (in the debt entry for libc): the host's own limit still applies below these numbers (on Windows a path whose host form is longer than MAX_PATH fails with ENOENT); a backslash counts as a separator for the component length (the guest resolver turns it into /), while FreeBSD treats it as a name character; sceNgs2ParseWaveformFile resolves without a try block, so a long component ends in an uncaught filesystem_error there where a missing file ended in a runtime_error (both end the title); a path through a regular file is not always ENOTDIR.

No title evidence: found by calling the file functions with oversized names. This is FreeBSD conformance. Replaces #5006 (closed), rebased on current main.
Fixes #8163

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main + these commits:

  • guest_path_name_length: Exit code 0xc0000409 without the changes to General.cpp and Stdio.cpp, passes with them.
  • guest_filesystem, guest_fopen_long_host_path, guest_path_case, guest_path_drive_component, guest_working_directory and guest_directory pass (7 of 7 with the new test).
  • python tools/check_conventions.py --base upstream/main: passes (a warning about the length of the debt entry).
  • Not tested: Linux, a console, a title run, pr_overlap (checked merge-tree and a gh search instead).

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4929502605 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8164). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T01:03:17Z. --- ### What `stat`, `open`, `mkdir`, `unlink`, `rmdir`, `rename`, `access` and the other calls that resolve a guest path answer `ENOENT` (and `rename` `EIO`) for a path name that FreeBSD refuses as too long, because the resolved host path does not exist. FreeBSD 11.4's `namei` ([`vfs_lookup.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_lookup.c#L328)) fails a path component above `NAME_MAX` (255 bytes) and a path of `MAXPATHLEN` (1024 bytes including the terminating NUL) with `ENAMETOOLONG` (63). `Resolve()` in `General.cpp` (behind `ResolvePath_nid_no_patch`) now checks the whole path (1024 bytes) on the guest string before resolving it, and a component above 255 bytes only when every component before it exists and is a directory (`namei` resolves in order, so a missing directory earlier in the path still answers `ENOENT`). Both throw a `filesystem_error` with `filename_too_long`; `FilesystemError` already maps that to 63 and `ResolvePathError_nid_no_patch`, which the kernel calls use, turns it into the errno. A name of exactly 255 bytes is not affected. `chflags` resolved its path with the throwing form and without a try block, so a long name would have ended the title once this check exists. A second commit makes it use `ResolvePathError_nid_no_patch` like `chmod`; `guest_path_name_length` has a `chflags` case for it. The third commit adds a technical debt entry. Limits (in the debt entry for libc): the host's own limit still applies below these numbers (on Windows a path whose host form is longer than `MAX_PATH` fails with `ENOENT`); a backslash counts as a separator for the component length (the guest resolver turns it into `/`), while FreeBSD treats it as a name character; `sceNgs2ParseWaveformFile` resolves without a try block, so a long component ends in an uncaught `filesystem_error` there where a missing file ended in a `runtime_error` (both end the title); a path through a regular file is not always `ENOTDIR`. No title evidence: found by calling the file functions with oversized names. This is FreeBSD conformance. Replaces #5006 (closed), rebased on current `main`. Fixes #8163 ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on `upstream/main` + these commits: - `guest_path_name_length`: `Exit code 0xc0000409` without the changes to `General.cpp` and `Stdio.cpp`, passes with them. - `guest_filesystem`, `guest_fopen_long_host_path`, `guest_path_case`, `guest_path_drive_component`, `guest_working_directory` and `guest_directory` pass (7 of 7 with the new test). - `python tools/check_conventions.py --base upstream/main`: passes (a warning about the length of the debt entry). - Not tested: Linux, a console, a title run, `pr_overlap` (checked `merge-tree` and a `gh` search instead). ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 01:19:46 +00:00 (Migrated from github.com)

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


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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7949 core/libs/prx/libkernel/File/src/Stdio.cpp L620-626

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 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6226 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libc.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 6879 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7081 docs/dev/debt/libc.md
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
PR 7201 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7332 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8037 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281070271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8164#issuecomment-6281070271). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T01:19:46Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7949](https://www.github.com/boykopovar/AnyPS5/pull/7949) | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L620-626](https://github.com/boykopovar/AnyPS5/blob/58f5b31e6fbbc12f4e864968e250a19428bd5cef/core/libs/prx/libkernel/File/src/Stdio.cpp#L620-L626) | | | 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 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7386](https://www.github.com/boykopovar/AnyPS5/pull/7386) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` | | [PR 8037](https://www.github.com/boykopovar/AnyPS5/pull/8037) | `docs/dev/debt/libc.md` |
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!8164
No description provided.