libc: guest_standard_streams aborts on Windows because a second ungetc on an unbuffered stream fails #17423

Closed
opened 2026-11-08 19:25:52 +00:00 by Danigamer05 · 0 comments
Danigamer05 commented 2026-11-08 19:25:52 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-08T19:25:52Z.


What happens

guest_standard_streams aborts on Windows (Exit code 0xc0000409) on current main: the second ungetc on an unbuffered stream returns EOF in CheckGetdelimAndGetline.

Title, test or build step

ctest guest_standard_streams (core/libs/tests/GuestStandardStreams.cpp, the read-error fixture added with #12920)

AnyPS5 commit

main 095ff72367c, nothing merged on top. The same abort appears with #17331 merged on top, in that pull request's hosted windows job (run).

System

Windows 11 Pro 26200, MinGW-w64 GCC 15.2 (UCRT), Ninja, Release. GPU not involved.

Steps to reproduce

cmake -S . -B b -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
cmake --build b --target guest_standard_stream_tests
ctest --test-dir b -R "^guest_standard_streams$" --output-on-failure

It stops within half a second, every run (5 of 5 on the merge with #17331, 3 of 3 on plain main).

Log

1/1 Test #1078: guest_standard_streams ...........Exit code 0xc0000409***Exception:   0.35 sec

gdb on the test binary:

#0  ucrtbase!abort ()
#1  CheckGetdelimAndGetline() [clone .cold] ()

With Require temporarily changed to print __LINE__, the failing check is line 473:

setvbuf_nid_postfix(midReadStream, nullptr, 2, 0);
Require(fgetc_nid_postfix(midReadStream) == 'a');
Require(fgetc_nid_postfix(midReadStream) == 'b');
Require(ungetc_nid_postfix('b', midReadStream) == 'b');
Require(ungetc_nid_postfix('a', midReadStream) == 'a');   // fails

What was checked

ungetc_nid_postfix (core/libs/prx/libc/src/StandardStreams.cpp) forwards to the host std::ungetc. The UCRT keeps a single pushback byte for an _IONBF stream, so the second call fails; FreeBSD's ungetc grows its own pushback buffer and accepts it, which is what the fixture expects. Either the fixture should push back only one byte on an unbuffered stream, or ungetc needs a pushback buffer of its own on Windows to match FreeBSD.

Not checked on Linux or macOS, where the host ungetc may accept more than one byte. The hosted Windows job on main was still queued at the time of writing.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6274710283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/17423). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-08T19:25:52Z. --- ### What happens `guest_standard_streams` aborts on Windows (`Exit code 0xc0000409`) on current `main`: the second `ungetc` on an unbuffered stream returns `EOF` in `CheckGetdelimAndGetline`. ### Title, test or build step ctest `guest_standard_streams` (`core/libs/tests/GuestStandardStreams.cpp`, the read-error fixture added with #12920) ### AnyPS5 commit `main` `095ff72367c`, nothing merged on top. The same abort appears with #17331 merged on top, in that pull request's hosted `windows` job ([run](https://github.com/boykopovar/AnyPS5/actions/runs/42508951938/job/128819242254)). ### System Windows 11 Pro 26200, MinGW-w64 GCC 15.2 (UCRT), Ninja, Release. GPU not involved. ### Steps to reproduce ``` cmake -S . -B b -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON cmake --build b --target guest_standard_stream_tests ctest --test-dir b -R "^guest_standard_streams$" --output-on-failure ``` It stops within half a second, every run (5 of 5 on the merge with #17331, 3 of 3 on plain `main`). ### Log ``` 1/1 Test #1078: guest_standard_streams ...........Exit code 0xc0000409***Exception: 0.35 sec ``` gdb on the test binary: ``` #0 ucrtbase!abort () #1 CheckGetdelimAndGetline() [clone .cold] () ``` With `Require` temporarily changed to print `__LINE__`, the failing check is line 473: ```cpp setvbuf_nid_postfix(midReadStream, nullptr, 2, 0); Require(fgetc_nid_postfix(midReadStream) == 'a'); Require(fgetc_nid_postfix(midReadStream) == 'b'); Require(ungetc_nid_postfix('b', midReadStream) == 'b'); Require(ungetc_nid_postfix('a', midReadStream) == 'a'); // fails ``` ### What was checked `ungetc_nid_postfix` (`core/libs/prx/libc/src/StandardStreams.cpp`) forwards to the host `std::ungetc`. The UCRT keeps a single pushback byte for an `_IONBF` stream, so the second call fails; FreeBSD's `ungetc` grows its own pushback buffer and accepts it, which is what the fixture expects. Either the fixture should push back only one byte on an unbuffered stream, or `ungetc` needs a pushback buffer of its own on Windows to match FreeBSD. Not checked on Linux or macOS, where the host `ungetc` may accept more than one byte. The hosted Windows job on `main` was still queued at the time of writing.
Sign in to join this conversation.
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#17423
No description provided.