fix(libc): reject incompatible fdopen access modes on Windows #4728
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4728"
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-12T19:53:29Z.
What
On Windows, UCRT
_fdopenaccepts descriptors whose access does not match the requested stream mode. Validate the existing descriptor before wrapping it: incompatible modes return EINVAL, closed descriptors return EBADF, and rejection retains the descriptor and its state. The reference is FreeBSD 11.4fdopen.c, recorded in libc debt.Reuse the existing Windows handle/access query used by
fcntlthrough internal static-inline libc helpers. Perform the validation before main'sAppendThroughDescriptor, which can replace the descriptor and enable append mode. Preserve the upstream append behavior and its regression tests.Tested
Windows, MinGW-w64 GCC 15.2.0, Release, BUILD_TESTING=ON, rebased on main
c13dc7e6b.The original access/mode regression failed before the fix. Full project build exits 0 and 14/14 relevant tests pass (1.40 s): standard streams, fcntl, file streams/position, dup, scalar/vector I/O, patched libraries and all six file-lock cases. The standard-stream test includes main's append checks and the 18 access/mode combinations plus a closed descriptor.
Rejected modes preserve the underlying Windows handle, file offset and contents. A raw write after rejecting write-only
a+must overwrite at offset 2 and advance to 3, detecting an accidental append flag even if the wrapped stream was rejected. The POSIX side also checks the original descriptor flags; Linux execution was not run here.Patched/unpatched libc and libkernel PE export audits find no WindowsDescriptor helper/callback/state exports.
git diff --checkand the committed branch/PR conventions check pass. No game or PS5 console was run; no performance improvement is claimed.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-13T03:55:21Z.
Windows test: head
40b311b61merged onto currentmain495bf91a0(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_standard_stream: guest_standard_streams passed (1 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:25:06Z.
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)docs/dev/debt/libc.mdL4core/libs/tests/GuestStandardStreams.cppL431-432core/libs/tests/GuestStandardStreams.cppL431-432Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:34:32Z.
Checked the diff against FreeBSD
fdopen.csemantics, the fcntl helper refactor (mechanical), the tests and the debt line; Linux build and ctest are green (217 tests). Windows behaviour is covered by the Windows build run before merge; merging once it is green.