fix(libkernel): reject ftruncate on non-file Windows handles #4923

Merged
MarcZX10 merged 1 commit from upstream-pr/4923 into main 2026-10-14 01:25:28 +00:00
MarcZX10 commented 2026-10-13 04:22:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T04:22:48Z.


What

Fixes #4921. Carries David's 971fb51ef commit, preserving his original commit authorship. On Windows, ftruncate and sceKernelFtruncate now return EINVAL for pipes, directory descriptors and /dev/urandom, matching Linux and FreeBSD behavior. Disk-file truncation, closed descriptors and shared-memory handling keep their existing paths.

The change checks the Windows handle type before _chsize_s; the regression checks ensure pipe contents remain intact and the non-file descriptors return EINVAL.

Tested

Local Linux, GCC 12.2, Release, BUILD_TESTING=ON:

  • Built guest_filesystem_tests; CTest guest_filesystem passed (1/1).
  • tools/check_conventions.py --base upstream/main: passed.
  • tools/check_test_registration.py: passed (757 test executables registered; no new target).
  • git diff --check upstream/main...HEAD: passed.
  • The existing Linux implementation already returns EINVAL; this run confirms the added cross-platform assertions pass on Linux. I did not run Windows locally or relink a title.

David reports Windows red/green results and a full CTest run in issue #4921, including the regression failing with main's Stdio.cpp and passing with his fix.

Checklist

  • Based on current main; no open PR implements the same function behavior
  • 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 or investigation files added to the repository
  • No new third-party code
  • Generic behavior, not title-specific
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4838325532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4923). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T04:22:48Z. --- ### What Fixes #4921. Carries David's `971fb51ef` commit, preserving his original commit authorship. On Windows, `ftruncate` and `sceKernelFtruncate` now return `EINVAL` for pipes, directory descriptors and `/dev/urandom`, matching Linux and FreeBSD behavior. Disk-file truncation, closed descriptors and shared-memory handling keep their existing paths. The change checks the Windows handle type before `_chsize_s`; the regression checks ensure pipe contents remain intact and the non-file descriptors return `EINVAL`. ### Tested Local Linux, GCC 12.2, Release, `BUILD_TESTING=ON`: - Built `guest_filesystem_tests`; CTest `guest_filesystem` passed (1/1). - `tools/check_conventions.py --base upstream/main`: passed. - `tools/check_test_registration.py`: passed (757 test executables registered; no new target). - `git diff --check upstream/main...HEAD`: passed. - The existing Linux implementation already returns `EINVAL`; this run confirms the added cross-platform assertions pass on Linux. I did not run Windows locally or relink a title. David reports Windows red/green results and a full CTest run in [issue #4921](https://github.com/boykopovar/AnyPS5/issues/4921), including the regression failing with `main`'s `Stdio.cpp` and passing with his fix. ### Checklist - [x] Based on current `main`; no open PR implements the same function behavior - [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 or investigation files added to the repository - [x] No new third-party code - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 06:15:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:15:32Z.


Windows test: head 097bc538e merged onto current main fe8d3eba0 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_filesystem: guest_filesystem passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139506876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4923#issuecomment-6139506876). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T06:15:32Z. --- Windows test: head `097bc538e` merged onto current `main` `fe8d3eba0` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `guest_filesystem`: guest_filesystem passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-13 12:00:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T12:00:19Z.


Windows counter-test (follow-up to the earlier Windows run): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, this PR merged onto main 2a2a3dc65. guest_filesystem passes with the PR; with the PR's source files replaced by main's, same test, it aborts at line 261 (guest errno 22, Win32 error 5).

Not tested: Linux, a console, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145052909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4923#issuecomment-6145052909). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T12:00:19Z. --- Windows counter-test (follow-up to the earlier Windows run): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, this PR merged onto `main` `2a2a3dc65`. `guest_filesystem` passes with the PR; with the PR's source files replaced by `main`'s, same test, it aborts at line 261 (guest errno 22, Win32 error 5). Not tested: Linux, a console, a title run. AI-assisted (Claude Code).
github-actions[bot] commented 2026-10-13 14:41:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T14:41:56Z.


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
#4968 core/libs/prx/libkernel/File/src/Stdio.cpp L112
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148136405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4923#issuecomment-6148136405). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T14:41:56Z. --- <!-- 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 | |---|---|---|---| | #4968 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L112](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/prx/libkernel/File/src/Stdio.cpp#L112) | | |
xXPBSXx commented 2026-10-14 00:55:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T00:55:26Z.


Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, -j4: head 097bc538e of this PR merged onto main ce5c83953 (clean merge, 2 files; the description reports Linux only).

  • guest_filesystem passes (0.30 s, ctest).
  • With core/libs/prx/libkernel/File/src/Stdio.cpp taken back to main and the PR's new test lines kept, guest_filesystem fails (Filesystem check failed at line 286 (guest errno 22, Win32 error 5), exit code 0xc0000409).
  • Not run: Linux, a console, a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158441958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4923#issuecomment-6158441958). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T00:55:26Z. --- Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, `-j4`: head `097bc538e` of this PR merged onto `main` `ce5c83953` (clean merge, 2 files; the description reports Linux only). - `guest_filesystem` passes (0.30 s, ctest). - With `core/libs/prx/libkernel/File/src/Stdio.cpp` taken back to `main` and the PR's new test lines kept, `guest_filesystem` fails (`Filesystem check failed at line 286 (guest errno 22, Win32 error 5)`, exit code `0xc0000409`). - Not run: Linux, a console, a title. AI-assisted (Claude Code).
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!4923
No description provided.