fix(libkernel): reject invalid ftruncate descriptors safely #5980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5980"
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 Ondra97 on 2026-10-14T18:02:57Z.
What
On Windows,
ftruncateandsceKernelFtruncatewith an invalid or closed descriptor reach_chsize_s's invalid-parameter handler. With the default handler this aborts the process instead of returningEBADF.Reject an invalid native handle before resizing and use the existing thread-local CRT suppression around
_chsize_s, preserving the caller's handler. Microsoft documents the invalid-descriptor callback that requires this handling. The regression checks both guest APIs with negative, closed and out-of-range descriptors at zero and nonzero lengths, checks handler restoration, and verifies that the real file is intact. The existing shrinking, extension and permission cases still run.Tested
I tested on Windows 11 Pro, MinGW-w64 GCC 15.2.0 (WinLibs), Release/Ninja, with
BUILD_TESTING=ON, outside the sandbox for the native filesystem cases.maind9bfa0f3a, the new regression reports 12 CRT parameter-handler invocations and fails.guest_truncate,guest_filesystem,guest_aio_bad_descriptorsandguest_duppass (4/4, 0.26 s).8ba869d30, full default Windows build, conventions andgit diff --checkpass.ftruncatewrapper does not implement this Windows native-handle fix. The focused repository overlap check is clean.Linux/macOS and a retail title were not run; production changes are inside the existing Windows branch.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in technical debt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T09:26:48Z.
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)core/libs/prx/libkernel/File/src/Stdio.cppL118-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/libkernel/File/src/Stdio.cppcore/libs/tests/GuestTruncate.cppcore/libs/prx/libkernel/File/src/Stdio.cppcore/libs/prx/libkernel/File/src/Stdio.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:58:41Z.
Checked the diff against the existing
WithoutParameterHandlerusage inStdio.cppand the newGuestTruncateregression (negative, closed and out-of-range descriptors, both guest APIs, handler restored). Build and ctest are green on Linux; the Windows path is covered by the Windows build run before merge. Merging.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:23:06Z.
Re-checked against current main: the diff still applies cleanly and
NativeFtruncateis unchanged by the recentStdio.cppmerges. Build and ctest are green on Linux (guest_truncateincluded); the Windows path is covered by the Windows build run before merge. Merging.