You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(libc): reject incompatible fdopen access modes on Windows - #4728
On Windows, UCRT _fdopen accepts 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.4 fdopen.c, recorded in libc debt.
Reuse the existing Windows handle/access query used by fcntl through internal static-inline libc helpers. Perform the validation before main's AppendThroughDescriptor, 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 c13dc7e.
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 --check and the committed branch/PR conventions check pass. No game or PS5 console was run; no performance improvement is claimed.
Checklist
Based on current main; no other open PR implements the same functions
Windows test: head 40b311b61 merged onto current main495bf91a0 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_standard_stream: guest_standard_streams 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.
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.
Checked the diff against FreeBSD fdopen.c semantics, 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 c13dc7e.
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)