libc: align fgetwc conversion/state with mbrtowc and verify fgetws edge cases #8897

Closed
opened 2026-10-21 05:00:26 +00:00 by UnhealthyKraken · 8 comments
UnhealthyKraken commented 2026-10-21 05:00:26 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T05:00:26Z.


Observed behavior

In a standalone Windows x86-64 Release probe, fgetwc returns 0x1F600 for the UTF-8 bytes F0 9F 98 80, while fgetws on the same bytes stores a single 16-bit 0xF600 followed by NUL. The source directly narrows the 32-bit result to char16_t at FormattingWide.cpp.

This reports the current implementation's conversion loss, not a measured PS5 expected result. We need to establish the console's fgetwc/fgetws contract for supplementary characters before choosing a fix: a UTF-16 surrogate pair, rejection, or another console-specific result must not be guessed.

Environment and validation

Windows x86-64, MinGW-w64 GCC15.2, Release. Library built in an isolated checkout on aa408677b0e794cf59f314ebcf9a716ede638295; StandardStreams.cpp, FormattingWide.cpp and FileStream.hpp are unchanged on inspected upstream main c68a27cc4. Only own temporary streams used; no game, firmware binary or proprietary capture.

The existing guest_standard_streams test passes. The six-case probe below records:


supplementary wc=0001f600 errno=123 ws=ok units=f600,0000,5555,5555 guard=5555 errno=123

overlong-nul wc=00000000 errno=123 ws=ok units=0000,0000,5555,5555 guard=5555 errno=123

surrogate wc=0000d800 errno=123 ws=ok units=d800,0000,5555,5555 guard=5555 errno=123

above-unicode wc=00110000 errno=123 ws=ok units=0000,0000,5555,5555 guard=5555 errno=123

continuation wc=ffffffff errno=86 ws=null units=5555,5555,5555,5555 guard=5555 errno=86

truncated wc=ffffffff errno=86 ws=null units=5555,5555,5555,5555 guard=5555 errno=86

The byte sequences are named descriptively relative to Unicode scalar-value UTF-8. Acceptance alone is not proof that they differ from PS5: the current debt explicitly records legacy conversion behavior in other multibyte APIs. Their behavior needs measurement separately. The important reproducible observation here is the 32-to-16-bit loss between these two stream functions.

Source-only reproducer

Compile from the checkout root with its MinGW toolchain, -std=c++20 -O2 -Icore/libs, and link the built unpatched libc.prx. Put the unpatched library directory and toolchain runtime directory on PATH. For example, save as work/wide-stream-probe.cpp and use:


g++ -std=c++20 -O2 -Icore/libs work/wide-stream-probe.cpp build/core/libs/libs/unpatched/libc.prx -o work/wide-stream-probe.exe


#include "prx/libc/include/FileStream.hpp"

#include "prx/libc/include/general/VabiMacros.hpp"

#include <array>

#include <cstdint>

#include <cstdio>

#include <cstdlib>

extern "C" {

std::int32_t APS5_VABI fgetwc_nid_postfix(FileStream*);

char16_t* APS5_VABI fgetws_nid_postfix(char16_t*,int,FileStream*);

int APS5_VABI fclose_nid_postfix(FileStream*);

int* APS5_VABI __error_nid_postfix();

}

void Probe(const char* name,const unsigned char* bytes,std::size_t size) {

    auto* file=std::tmpfile();

    if (!file) std::abort();

    FileStream stream(file);

    if (std::fwrite(bytes,1,size,file)!=size) std::abort();

    std::rewind(file);

    *__error_nid_postfix()=123;

    const auto wc=fgetwc_nid_postfix(&stream);

    const auto wcError=*__error_nid_postfix();

    std::rewind(file);

    std::array<char16_t,5> out{0x5555,0x5555,0x5555,0x5555,0x5555};

    *__error_nid_postfix()=123;

    const auto* result=fgetws_nid_postfix(out.data(),4,&stream);

    std::printf("%s wc=%08x errno=%d ws=%s units=%04x,%04x,%04x,%04x guard=%04x errno=%d\n",name,unsigned(wc),wcError,result?"ok":"null",unsigned(out[0]),unsigned(out[1]),unsigned(out[2]),unsigned(out[3]),unsigned(out[4]),*__error_nid_postfix());

    if (fclose_nid_postfix(&stream)!=0) std::abort();

}

int main() {

    const unsigned char supplementary[]{0xf0,0x9f,0x98,0x80};

    const unsigned char overlong[]{0xc0,0x80};

    const unsigned char surrogate[]{0xed,0xa0,0x80};

    const unsigned char tooHigh[]{0xf4,0x90,0x80,0x80};

    const unsigned char continuation[]{0x80};

    const unsigned char truncated[]{0xe2,0x82};

    Probe("supplementary",supplementary,sizeof supplementary);

    Probe("overlong-nul",overlong,sizeof overlong);

    Probe("surrogate",surrogate,sizeof surrogate);

    Probe("above-unicode",tooHigh,sizeof tooHigh);

    Probe("continuation",continuation,sizeof continuation);

    Probe("truncated",truncated,sizeof truncated);

}

Scope / overlap

Merged #5816 introduced fgetws; open #8479 adds stream scanning using fgetwc and related push-back. This report does not duplicate those exports or propose changing their branch. Current all-state searches for fgetwc, fgetws+surrogate and wide+supplementary found no focused report for this case. No code change proposed until the console contract is established. No Linux/macOS execution yet.

AI-assisted investigation and reproducer; I ran the Windows probe and existing stream test locally.

Evidence update (2026-10-22)

Contributor disassembly of three bundled builds and the separately attributed system-module measurements are summarized in the follow-up reply. The low-16-bit fgetws store is observed in those bundled libraries; the remaining discrepancy is the host fgetwc conversion/state path, plus size<2 and partial-read-error behavior. The bundled converter tables and malformed/four-byte behavior remain unverified. Open #8855 tracks the separate multibyte implementation work. The original report above is retained as reproduction history, not as proof that the narrowing itself differs from firmware.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5954635699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T05:00:26Z. --- ### Observed behavior In a standalone Windows x86-64 Release probe, `fgetwc` returns `0x1F600` for the UTF-8 bytes `F0 9F 98 80`, while `fgetws` on the same bytes stores a single 16-bit `0xF600` followed by NUL. The source directly narrows the 32-bit result to `char16_t` at [FormattingWide.cpp](https://github.com/boykopovar/AnyPS5/blob/c68a27cc4/core/libs/prx/libc/src/FormattingWide.cpp#L414). This reports the current implementation's conversion loss, **not a measured PS5 expected result**. We need to establish the console's `fgetwc`/`fgetws` contract for supplementary characters before choosing a fix: a UTF-16 surrogate pair, rejection, or another console-specific result must not be guessed. ### Environment and validation Windows x86-64, MinGW-w64 GCC15.2, Release. Library built in an isolated checkout on `aa408677b0e794cf59f314ebcf9a716ede638295`; `StandardStreams.cpp`, `FormattingWide.cpp` and `FileStream.hpp` are unchanged on inspected upstream main `c68a27cc4`. Only own temporary streams used; no game, firmware binary or proprietary capture. The existing `guest_standard_streams` test passes. The six-case probe below records: ```text supplementary wc=0001f600 errno=123 ws=ok units=f600,0000,5555,5555 guard=5555 errno=123 overlong-nul wc=00000000 errno=123 ws=ok units=0000,0000,5555,5555 guard=5555 errno=123 surrogate wc=0000d800 errno=123 ws=ok units=d800,0000,5555,5555 guard=5555 errno=123 above-unicode wc=00110000 errno=123 ws=ok units=0000,0000,5555,5555 guard=5555 errno=123 continuation wc=ffffffff errno=86 ws=null units=5555,5555,5555,5555 guard=5555 errno=86 truncated wc=ffffffff errno=86 ws=null units=5555,5555,5555,5555 guard=5555 errno=86 ``` The byte sequences are named descriptively relative to Unicode scalar-value UTF-8. Acceptance alone is not proof that they differ from PS5: the current debt explicitly records legacy conversion behavior in other multibyte APIs. Their behavior needs measurement separately. The important reproducible observation here is the 32-to-16-bit loss between these two stream functions. ### Source-only reproducer Compile from the checkout root with its MinGW toolchain, `-std=c++20 -O2 -Icore/libs`, and link the built unpatched `libc.prx`. Put the unpatched library directory and toolchain runtime directory on PATH. For example, save as `work/wide-stream-probe.cpp` and use: ```text g++ -std=c++20 -O2 -Icore/libs work/wide-stream-probe.cpp build/core/libs/libs/unpatched/libc.prx -o work/wide-stream-probe.exe ``` ```cpp #include "prx/libc/include/FileStream.hpp" #include "prx/libc/include/general/VabiMacros.hpp" #include <array> #include <cstdint> #include <cstdio> #include <cstdlib> extern "C" { std::int32_t APS5_VABI fgetwc_nid_postfix(FileStream*); char16_t* APS5_VABI fgetws_nid_postfix(char16_t*,int,FileStream*); int APS5_VABI fclose_nid_postfix(FileStream*); int* APS5_VABI __error_nid_postfix(); } void Probe(const char* name,const unsigned char* bytes,std::size_t size) { auto* file=std::tmpfile(); if (!file) std::abort(); FileStream stream(file); if (std::fwrite(bytes,1,size,file)!=size) std::abort(); std::rewind(file); *__error_nid_postfix()=123; const auto wc=fgetwc_nid_postfix(&stream); const auto wcError=*__error_nid_postfix(); std::rewind(file); std::array<char16_t,5> out{0x5555,0x5555,0x5555,0x5555,0x5555}; *__error_nid_postfix()=123; const auto* result=fgetws_nid_postfix(out.data(),4,&stream); std::printf("%s wc=%08x errno=%d ws=%s units=%04x,%04x,%04x,%04x guard=%04x errno=%d\n",name,unsigned(wc),wcError,result?"ok":"null",unsigned(out[0]),unsigned(out[1]),unsigned(out[2]),unsigned(out[3]),unsigned(out[4]),*__error_nid_postfix()); if (fclose_nid_postfix(&stream)!=0) std::abort(); } int main() { const unsigned char supplementary[]{0xf0,0x9f,0x98,0x80}; const unsigned char overlong[]{0xc0,0x80}; const unsigned char surrogate[]{0xed,0xa0,0x80}; const unsigned char tooHigh[]{0xf4,0x90,0x80,0x80}; const unsigned char continuation[]{0x80}; const unsigned char truncated[]{0xe2,0x82}; Probe("supplementary",supplementary,sizeof supplementary); Probe("overlong-nul",overlong,sizeof overlong); Probe("surrogate",surrogate,sizeof surrogate); Probe("above-unicode",tooHigh,sizeof tooHigh); Probe("continuation",continuation,sizeof continuation); Probe("truncated",truncated,sizeof truncated); } ``` ### Scope / overlap Merged #5816 introduced `fgetws`; open #8479 adds stream scanning using `fgetwc` and related push-back. This report does not duplicate those exports or propose changing their branch. Current all-state searches for `fgetwc`, `fgetws`+surrogate and wide+supplementary found no focused report for this case. No code change proposed until the console contract is established. No Linux/macOS execution yet. AI-assisted investigation and reproducer; I ran the Windows probe and existing stream test locally. ### Evidence update (2026-10-22) Contributor disassembly of three bundled builds and the separately attributed system-module measurements are summarized in [the follow-up reply](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6343065503). The low-16-bit fgetws store is observed in those bundled libraries; the remaining discrepancy is the host fgetwc conversion/state path, plus size<2 and partial-read-error behavior. The bundled converter tables and malformed/four-byte behavior remain unverified. Open #8855 tracks the separate multibyte implementation work. The original report above is retained as reproduction history, not as proof that the narrowing itself differs from firmware.
shravanveeravali-lab commented 2026-10-21 14:44:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by shravanveeravali-lab on 2026-10-21T14:44:58Z.


I traced the implementation in FormattingWide.cpp. fgetwc_nid_postfix() returns a 32-bit decoded code point, while fgetws_nid_postfix() casts it directly to char16_t, which truncates supplementary characters such as U+1F600.

Before proposing a fix, could someone confirm the expected console behavior for supplementary characters in fgetws? Should the output use a UTF-16 surrogate pair, or does the console follow a different contract? I also noticed the decoder may accept malformed UTF-8 sequences, so I'd like to confirm the intended error behavior before adding regression tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6318859212 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6318859212). Originally posted by [shravanveeravali-lab](https://github.com/shravanveeravali-lab) on 2026-10-21T14:44:58Z. --- I traced the implementation in `FormattingWide.cpp`. `fgetwc_nid_postfix()` returns a 32-bit decoded code point, while `fgetws_nid_postfix()` casts it directly to `char16_t`, which truncates supplementary characters such as U+1F600. Before proposing a fix, could someone confirm the expected console behavior for supplementary characters in `fgetws`? Should the output use a UTF-16 surrogate pair, or does the console follow a different contract? I also noticed the decoder may accept malformed UTF-8 sequences, so I'd like to confirm the intended error behavior before adding regression tests.
UnhealthyKraken commented 2026-10-22 03:16:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T03:16:26Z.


I do not have a measured console contract for supplementary characters or malformed sequences. The reproducible fact in this issue is the current Windows conversion loss: fgetwc yields 0x1f600, then fgetws stores 0xf600. It does not establish that the console emits a surrogate pair, rejects the character, or follows the same narrowing behavior.

The malformed-sequence results are also current-model observations, not confirmed PS5 errors. A fix needs attributable results for output units/bounds, return value, errno and stream consumption, including a buffer boundary within a supplementary character. Until that evidence is available I would keep the encoding question open rather than prescribe a surrogate-pair or strict-decoder change. No new console run is claimed here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331807392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6331807392). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T03:16:26Z. --- I do not have a measured console contract for supplementary characters or malformed sequences. The reproducible fact in this issue is the current Windows conversion loss: `fgetwc` yields `0x1f600`, then `fgetws` stores `0xf600`. It does not establish that the console emits a surrogate pair, rejects the character, or follows the same narrowing behavior. The malformed-sequence results are also current-model observations, not confirmed PS5 errors. A fix needs attributable results for output units/bounds, return value, errno and stream consumption, including a buffer boundary within a supplementary character. Until that evidence is available I would keep the encoding question open rather than prescribe a surrogate-pair or strict-decoder change. No new console run is claimed here.
JJenkx commented 2026-10-22 03:48:51 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T03:48:51Z.


Data point for the console's fgetws contract, read from disassembly (not measured on a console). The source is the libc.prx that three titles ship in sce_module/: PPSA13934, PPSA07923 and PPSA05916. All three have the same 133-byte fgetws (F81hKe2k2tg). The addresses below are from PPSA13934's copy, where fgetws is at 0x6cab0 and fgetwc (bzbQ5zQ2Y3g) is at 0x6c7a0.

The 16-bit narrowing is the console's own behaviour. fgetws calls fgetwc and stores only the low 16 bits of its result:

call   fgetwc
cmp    $0xffffffff,%eax
je     done
mov    %ax,(%rbx)
add    $0x2,%rbx
dec    %r12d
cmp    $0xa,%eax
jne    loop

There is no surrogate pair and no rejection, so on this console libc.prx a supplementary character that fgetwc returns as 0x1F600 is stored as 0xF600, as in this issue's probe. The '\n' test compares all 32 bits of the fgetwc result.

Two differences from fgetws_nid_postfix on current main:

Case Console fgetws main
size < 2 Returns null without writing the buffer (cmp $0x2,%esi; jge, else xor %r14d,%r14d). For size == 1, stores a NUL and returns the buffer. For size <= 0, also sets the stream error and errno 22.
fgetwc returns -1 after some characters were stored Stores the NUL and returns the buffer. It doesn't check ferror: null is returned only when nothing was stored. Returns null when ferror is set.

Not settled here:

  • What the console's fgetwc decodes from F0 9F 98 80 or from the malformed sequences. I didn't read the 498-byte fgetwc.
  • The call made when bits 0xc of the stream's second flag byte are set (testb $0xc,0x1(%r15), then a call with 0).
  • These are titles' bundled libc.prx builds, not a system module.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332210691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6332210691). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T03:48:51Z. --- Data point for the console's `fgetws` contract, read from disassembly (not measured on a console). The source is the `libc.prx` that three titles ship in `sce_module/`: PPSA13934, PPSA07923 and PPSA05916. All three have the same 133-byte `fgetws` (`F81hKe2k2tg`). The addresses below are from PPSA13934's copy, where `fgetws` is at 0x6cab0 and `fgetwc` (`bzbQ5zQ2Y3g`) is at 0x6c7a0. **The 16-bit narrowing is the console's own behaviour.** `fgetws` calls `fgetwc` and stores only the low 16 bits of its result: ``` call fgetwc cmp $0xffffffff,%eax je done mov %ax,(%rbx) add $0x2,%rbx dec %r12d cmp $0xa,%eax jne loop ``` There is no surrogate pair and no rejection, so on this console `libc.prx` a supplementary character that `fgetwc` returns as `0x1F600` is stored as `0xF600`, as in this issue's probe. The `'\n'` test compares all 32 bits of the `fgetwc` result. **Two differences from `fgetws_nid_postfix` on current `main`:** | Case | Console `fgetws` | `main` | |---|---|---| | `size < 2` | Returns null without writing the buffer (`cmp $0x2,%esi; jge`, else `xor %r14d,%r14d`). | For `size == 1`, stores a NUL and returns the buffer. For `size <= 0`, also sets the stream error and `errno` 22. | | `fgetwc` returns -1 after some characters were stored | Stores the NUL and returns the buffer. It doesn't check `ferror`: null is returned only when nothing was stored. | Returns null when `ferror` is set. | **Not settled here:** - What the console's `fgetwc` decodes from `F0 9F 98 80` or from the malformed sequences. I didn't read the 498-byte `fgetwc`. - The call made when bits `0xc` of the stream's second flag byte are set (`testb $0xc,0x1(%r15)`, then a call with 0). - These are titles' bundled `libc.prx` builds, not a system module.
JJenkx commented 2026-10-22 03:58:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T03:58:19Z.


Follow-up on fgetwc, from the same three bundled libc.prx copies (addresses from PPSA13934's: fgetwc 0x6c7a0, 498 bytes; read from disassembly, not measured).

The console's fgetwc returns one 16-bit unit, zero-extended, and decodes with the same routine as mbrtowc.

  • It converts into a 16-bit stack slot and returns that slot:
    movw   $0x0,-0x32(%rbp)
    lea    -0x32(%rbp),%rdi      ; destination: one 16-bit unit
    mov    %r15,%rsi             ; buffered bytes
    mov    %r14,%rdx             ; byte count
    mov    -0x40(%rbp),%rcx      ; conversion state at stream+0x60
    call   0x3bbe0
    ...
    movzwl -0x32(%rbp),%r14d     ; result
    
  • 0x3bbe0 is not an export. It loads a table pointer into r8 and calls a table-driven converter. mbrtowc (qVHpv0PxouI) calls the same 0x3bbe0, while mbrtoc16 takes a different path.
  • A result of -3 consumes no bytes (cmp $0xfffffffd,%eax; cmovne), so one input can come out as several 16-bit units over several calls, with the state kept in the stream.
  • A result of -2 makes it refill and retry while fewer than 6 bytes are buffered (cmp $0x5,%r14; ja fails). With 6 or more, or when the refill gets nothing, it sets the stream's error bit (orb $0x2,0x1(%r13)) and returns -1.
  • A pushed-back unit is read back as 16 bits from stream+0x38 (movzwl (%rax)).

What this means for #8897:

  • On the console, fgetwc never returns 0x1F600. Its result is whatever the mbrtowc conversion of the title's locale produces, one 16-bit unit per call.
  • So the narrowing in fgetws loses nothing on the console.
  • On main, fgetwc decodes UTF-8 to a 32-bit value. Per the libc debt entry, this libc's mbrtowc keeps the single-byte C locale, so the two use different conversions.
  • A faithful fgetwc would decode through the same conversion as this libc's mbrtowc, with the state in the stream.

Not established:

  • What the table at 0x113bf8 encodes, that is whether the bundled libc.prx's default locale is single-byte or UTF-8. So the console's exact output for F0 9F 98 80 and for the malformed sequences is still open.
  • The calls before and after the read, and the one made when bits 0xc of the stream's second flag byte are set.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332325808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6332325808). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T03:58:19Z. --- Follow-up on `fgetwc`, from the same three bundled `libc.prx` copies (addresses from PPSA13934's: `fgetwc` 0x6c7a0, 498 bytes; read from disassembly, not measured). **The console's `fgetwc` returns one 16-bit unit, zero-extended, and decodes with the same routine as `mbrtowc`.** - It converts into a 16-bit stack slot and returns that slot: ``` movw $0x0,-0x32(%rbp) lea -0x32(%rbp),%rdi ; destination: one 16-bit unit mov %r15,%rsi ; buffered bytes mov %r14,%rdx ; byte count mov -0x40(%rbp),%rcx ; conversion state at stream+0x60 call 0x3bbe0 ... movzwl -0x32(%rbp),%r14d ; result ``` - 0x3bbe0 is not an export. It loads a table pointer into `r8` and calls a table-driven converter. `mbrtowc` (`qVHpv0PxouI`) calls the same 0x3bbe0, while `mbrtoc16` takes a different path. - A result of -3 consumes no bytes (`cmp $0xfffffffd,%eax; cmovne`), so one input can come out as several 16-bit units over several calls, with the state kept in the stream. - A result of -2 makes it refill and retry while fewer than 6 bytes are buffered (`cmp $0x5,%r14; ja` fails). With 6 or more, or when the refill gets nothing, it sets the stream's error bit (`orb $0x2,0x1(%r13)`) and returns -1. - A pushed-back unit is read back as 16 bits from stream+0x38 (`movzwl (%rax)`). **What this means for #8897:** - On the console, `fgetwc` never returns `0x1F600`. Its result is whatever the `mbrtowc` conversion of the title's locale produces, one 16-bit unit per call. - So the narrowing in `fgetws` loses nothing on the console. - On `main`, `fgetwc` decodes UTF-8 to a 32-bit value. Per the libc debt entry, this libc's `mbrtowc` keeps the single-byte C locale, so the two use different conversions. - A faithful `fgetwc` would decode through the same conversion as this libc's `mbrtowc`, with the state in the stream. **Not established:** - What the table at 0x113bf8 encodes, that is whether the bundled `libc.prx`'s default locale is single-byte or UTF-8. So the console's exact output for `F0 9F 98 80` and for the malformed sequences is still open. - The calls before and after the read, and the one made when bits `0xc` of the stream's second flag byte are set.
JJenkx commented 2026-10-22 04:25:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:25:40Z.


One more data point on the locale question, from the same bundled libc.prx (PPSA13934). Read from disassembly, not measured.

Exported _Getmbcurmax (U52BlHBvYvE, 9 bytes at 0x3a40) returns a signed byte from initialized data, and that byte is 3 in the file:

movsbq 0x10c698(%rip),%rax     ; vaddr 0x1100e0
ret

I found no instruction that writes that byte, and none that takes the address of anything around it; the only reference is this read. As far as a static reading shows, this libc.prx reports MB_CUR_MAX 3. That is a multibyte default consistent with UTF-8 limited to 16-bit units, not the single-byte C locale.

This fits the debt entry's console measurement that the system libSceLibcInternal's default locale converts UTF-8 (wctomb of U+263A gives E2 98 BA).

On main, _Getmbcurmax returns ___mb_cur_max, and the libc debt entry describes this libc's wctomb/wcrtomb/mbrtowc as single-byte with MB_CUR_MAX 1.

Still not established:

  • The state tables the shared converter uses (vaddr 0x113bf8) are in BSS and filled at run time, so I couldn't read the exact UTF-8 handling. Open points: 4-byte sequences such as F0 9F 98 80 (refused, or split with -3), overlong forms, and surrogates.
  • I couldn't rule out a write to the MB_CUR_MAX byte through a computed pointer.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332675536 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6332675536). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:25:40Z. --- One more data point on the locale question, from the same bundled `libc.prx` (PPSA13934). Read from disassembly, not measured. **Exported `_Getmbcurmax` (`U52BlHBvYvE`, 9 bytes at 0x3a40) returns a signed byte from initialized data, and that byte is 3 in the file:** ``` movsbq 0x10c698(%rip),%rax ; vaddr 0x1100e0 ret ``` I found no instruction that writes that byte, and none that takes the address of anything around it; the only reference is this read. As far as a static reading shows, this `libc.prx` reports `MB_CUR_MAX` 3. That is a multibyte default consistent with UTF-8 limited to 16-bit units, not the single-byte C locale. This fits the debt entry's console measurement that the system `libSceLibcInternal`'s default locale converts UTF-8 (`wctomb` of U+263A gives `E2 98 BA`). On `main`, `_Getmbcurmax` returns `___mb_cur_max`, and the libc debt entry describes this libc's `wctomb`/`wcrtomb`/`mbrtowc` as single-byte with `MB_CUR_MAX` 1. **Still not established:** - The state tables the shared converter uses (vaddr 0x113bf8) are in BSS and filled at run time, so I couldn't read the exact UTF-8 handling. Open points: 4-byte sequences such as `F0 9F 98 80` (refused, or split with -3), overlong forms, and surrogates. - I couldn't rule out a write to the `MB_CUR_MAX` byte through a computed pointer.
JJenkx commented 2026-10-22 04:28:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:28:41Z.


#8855 (hypermoist) settles part of what I left open above, for the firmware's libSceLibcInternal.sprx (12.00), by calling its exports directly. _Getmbcurmax returns 3, as in the bundled libc.prx here. Four-byte leads (≥ 0xF0) are invalid, and overlong forms and encoded surrogates decode. If the bundled libc.prx's converter follows the same rules, the console's fgetwc would fail on F0 9F 98 80 rather than return 0x1F600 or a surrogate pair. I haven't verified that for the bundled module, whose tables are filled at run time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332713297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6332713297). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T04:28:41Z. --- #8855 (hypermoist) settles part of what I left open above, for the firmware's `libSceLibcInternal.sprx` (12.00), by calling its exports directly. `_Getmbcurmax` returns 3, as in the bundled `libc.prx` here. Four-byte leads (≥ 0xF0) are invalid, and overlong forms and encoded surrogates decode. If the bundled `libc.prx`'s converter follows the same rules, the console's `fgetwc` would fail on `F0 9F 98 80` rather than return `0x1F600` or a surrogate pair. I haven't verified that for the bundled module, whose tables are filled at run time.
UnhealthyKraken commented 2026-10-22 14:20:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T14:20:27Z.


These follow-ups correct the interpretation of my original symptom: the low-16-bit store in fgetws is not itself evidence of a firmware bug. Your reading of the three bundled builds places the discrepancy earlier, in fgetwc using a different conversion path from the shared mbrtowc routine. I have recorded the source/build and disassembly-only limits, and linked the system-module measurements in open #8855 separately; they do not by themselves establish the bundled module's dynamically initialized tables. I am keeping this issue open for the conversion/state alignment and the independently reported size<2 / partial-read-error differences. Exact handling of four-byte sequences and malformed inputs in those bundled builds remains unverified; no widening or surrogate behavior has been invented.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343065503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6343065503). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T14:20:27Z. --- These follow-ups correct the interpretation of my original symptom: the low-16-bit store in `fgetws` is not itself evidence of a firmware bug. Your reading of the three bundled builds places the discrepancy earlier, in `fgetwc` using a different conversion path from the shared `mbrtowc` routine. I have recorded the source/build and disassembly-only limits, and linked the system-module measurements in open #8855 separately; they do not by themselves establish the bundled module's dynamically initialized tables. I am keeping this issue open for the conversion/state alignment and the independently reported size<2 / partial-read-error differences. Exact handling of four-byte sequences and malformed inputs in those bundled builds remains unverified; no widening or surrogate behavior has been invented.
MarcZX10 commented 2026-10-22 14:58:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:58:18Z.


I opened #9786 for the two separately evidenced fgetws cases: sizes below two return null without touching the buffer or stream error state, and a read error after partial output returns the null-terminated partial string while preserving the error indicator. The Linux focused standard-stream tests pass 3/3. The fgetwc conversion/state discrepancy remains open and is not claimed as fixed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343876859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8897#issuecomment-6343876859). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:58:18Z. --- I opened #9786 for the two separately evidenced `fgetws` cases: sizes below two return null without touching the buffer or stream error state, and a read error after partial output returns the null-terminated partial string while preserving the error indicator. The Linux focused standard-stream tests pass 3/3. The `fgetwc` conversion/state discrepancy remains open and is not claimed as fixed.
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#8897
No description provided.