fix(libc): format sizes, NaN signs, UTF-16 units, positions and unknown conversions as a PS5 does #10223

Merged
orezraey merged 5 commits from upstream-pr/10223 into main 2026-10-24 18:34:57 +00:00
orezraey commented 2026-10-23 14:29:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T14:29:45Z.


What

The narrow printf family measured on a retail PS5 (firmware 13.60) through libSceLibcInternal.sprx's snprintf from a payload process, on the points the debt file listed as unverified. The sources and console logs are in this gist (pfmt5 to pfmt7). I ran the same cases through AnyPS5 on Windows and fixed the five that differed:

Case Console Before
snprintf with a size above INT_MAX + 1, up to SIZE_MAX formats as usual -1 with EOVERFLOW, following FreeBSD
a negative NaN in %f, %e, %g, %a; %+f, % f of a NaN -nan, +nan, nan; %F gives -NAN nan always
%08f of a NaN pads with spaces ( -nan) the same, without the sign
%ls with a surrogate pair (U+1F600) each unit encoded alone: ED A0 BD ED B8 80 the pair joined: F0 9F 98 80
%100$d and above (400 measured) works throws above 99
an unknown conversion (%m, %k, %y, %5k, %-3y, %lk, %#k, %.2k, %0$d) % and its letter, padded to the width, # and precision ignored, no argument taken ([ %k], [%y ], [%k], %$d) %m printed strerror(errno); after #3987, # and precision threw

Lone surrogates, %.2ls cutting a whole character, and the zero flag padding infinities with spaces already matched.

On Linux, formats with an unknown conversion now go to the guest formatter, as %m did; glibc already prints NaN the console's way. The _s forms still throw for an unknown conversion, %m included, since they were not measured. Positions above 65535 throw. The debt entries are rewritten.

These are libSceLibcInternal.sprx's results; a title that ships its own libc.prx may differ. #9699, #9916 and #9927 edit the NaN lines of WindowsFormatting.hpp; whichever lands second keeps both changes. #3987 landed first and main is merged: its %q, %D/%O/%U, width, -, %5% and trailing-% behaviour is kept, and its unknown-conversion branch is folded into this PR's. Only the measured cases change: #, precision and a 0 without a width are ignored (%#k and %.2k print %k in pfmt7), so %#y and %.2y now print %y; +, space, ' and 0 with a width on an unknown conversion are unmeasured and still throw, as do the _s forms. On Linux a format with an unknown conversion goes to the same formatter, and the size given to glibc is capped at INT_MAX + 1, since glibc fails a SIZE_MAX size where the console formats.

Tested

Windows 11, MinGW (winlibs).

  • guest_formatting checks every row above, the counts, and positions 99 and 100. It fails on main and passes three runs in a row with the change, as do the 15 other formatting, scanning, wide, strftime and syslog tests.
  • The full suite passes (1075 tests).
  • Linux (WSL2 Arch, GCC 16.2, Release) at head 4756ead: cmake --build . --target guest_formatting_tests, then ctest -R "^guest_formatting$" --output-on-failure passes three runs in a row. Its %m, %k, %y, %lk and %0$d checks are not Windows-only, so they cover the new RequiresGuestFormatting routing.
  • At head 1393a91fdf (main merged after #3987): guest_formatting, guest_wide_formatting and guest_safe_errors pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2 Arch, GCC 16.2). Before the size cap, guest_formatting failed on Linux at the SIZE_MAX snprintf check, 3 of 3.
  • At head 30f054270f (the unmeasured unknown-conversion cases %0y, %+y, % y, %'y and %05y dropped from the tests; production still throws for +, space, ' and a zero flag with a width): guest_formatting, guest_wide_formatting and guest_safe_errors pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2 Arch, GCC 16.2).
  • tools/check_conventions.py passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9699, #9916, #9927, #9939, #9958, #10379; #9699, #9916, #9927, #9939, #9958, #10379 edit the same lines too (merge order only); #9552 edits the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4984345671 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10223). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T14:29:45Z. --- ### What The narrow printf family measured on a retail PS5 (firmware 13.60) through `libSceLibcInternal.sprx`'s `snprintf` from a payload process, on the points the debt file listed as unverified. The sources and console logs are in [this gist](https://gist.github.com/orezraey/f7719acde5c9b95f4b1aa944451e03c6) (`pfmt5` to `pfmt7`). I ran the same cases through AnyPS5 on Windows and fixed the five that differed: | Case | Console | Before | |---|---|---| | `snprintf` with a size above `INT_MAX + 1`, up to `SIZE_MAX` | formats as usual | -1 with `EOVERFLOW`, following FreeBSD | | a negative NaN in `%f`, `%e`, `%g`, `%a`; `%+f`, `% f` of a NaN | `-nan`, `+nan`, ` nan`; `%F` gives `-NAN` | `nan` always | | `%08f` of a NaN | pads with spaces (` -nan`) | the same, without the sign | | `%ls` with a surrogate pair (U+1F600) | each unit encoded alone: `ED A0 BD ED B8 80` | the pair joined: `F0 9F 98 80` | | `%100$d` and above (400 measured) | works | throws above 99 | | an unknown conversion (`%m`, `%k`, `%y`, `%5k`, `%-3y`, `%lk`, `%#k`, `%.2k`, `%0$d`) | `%` and its letter, padded to the width, `#` and precision ignored, no argument taken (`[ %k]`, `[%y ]`, `[%k]`, `%$d`) | `%m` printed `strerror(errno)`; after #3987, `#` and precision threw | Lone surrogates, `%.2ls` cutting a whole character, and the zero flag padding infinities with spaces already matched. On Linux, formats with an unknown conversion now go to the guest formatter, as `%m` did; glibc already prints NaN the console's way. The `_s` forms still throw for an unknown conversion, `%m` included, since they were not measured. Positions above 65535 throw. The debt entries are rewritten. These are `libSceLibcInternal.sprx`'s results; a title that ships its own `libc.prx` may differ. #9699, #9916 and #9927 edit the NaN lines of `WindowsFormatting.hpp`; whichever lands second keeps both changes. #3987 landed first and `main` is merged: its `%q`, `%D`/`%O`/`%U`, width, `-`, `%5%` and trailing-`%` behaviour is kept, and its unknown-conversion branch is folded into this PR's. Only the measured cases change: `#`, precision and a `0` without a width are ignored (`%#k` and `%.2k` print `%k` in `pfmt7`), so `%#y` and `%.2y` now print `%y`; `+`, space, `'` and `0` with a width on an unknown conversion are unmeasured and still throw, as do the `_s` forms. On Linux a format with an unknown conversion goes to the same formatter, and the size given to glibc is capped at `INT_MAX + 1`, since glibc fails a `SIZE_MAX` size where the console formats. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW (winlibs). - `guest_formatting` checks every row above, the counts, and positions 99 and 100. It fails on `main` and passes three runs in a row with the change, as do the 15 other formatting, scanning, wide, strftime and syslog tests. - The full suite passes (1075 tests). - Linux (WSL2 Arch, GCC 16.2, Release) at head `4756ead`: `cmake --build . --target guest_formatting_tests`, then `ctest -R "^guest_formatting$" --output-on-failure` passes three runs in a row. Its `%m`, `%k`, `%y`, `%lk` and `%0$d` checks are not Windows-only, so they cover the new `RequiresGuestFormatting` routing. - At head `1393a91fdf` (main merged after #3987): `guest_formatting`, `guest_wide_formatting` and `guest_safe_errors` pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2 Arch, GCC 16.2). Before the size cap, `guest_formatting` failed on Linux at the `SIZE_MAX` `snprintf` check, 3 of 3. - At head `30f054270f` (the unmeasured unknown-conversion cases `%0y`, `%+y`, `% y`, `%'y` and `%05y` dropped from the tests; production still throws for `+`, space, `'` and a zero flag with a width): `guest_formatting`, `guest_wide_formatting` and `guest_safe_errors` pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2 Arch, GCC 16.2). - `tools/check_conventions.py` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9699, #9916, #9927, #9939, #9958, #10379; #9699, #9916, #9927, #9939, #9958, #10379 edit the same lines too (merge order only); #9552 edits the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 14:37:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T14:37:51Z.

Review: CHANGES_REQUESTED


The Windows measurements and focused formatting coverage are useful, and the hosted conventions/relinker/register-context checks pass. Two items still need closing before this is ready for approval:

  1. Please run the focused formatting test on Linux against this exact head (including the new RequiresGuestFormatting routing for unknown conversions), and report the command/result. The PR description currently says Linux was not run, and hosted Linux/Windows product jobs are skipped.
  2. This changes WindowsFormatting.hpp's conversion branch alongside #3987, and the overlap report also lists several in-flight libc math PRs that edit the debt file. The repository checklist asks authors to agree on ordering for overlapping changes. Please coordinate with #3987's author and record the agreed order in Depends on (or confirm the changes are independent after the shared-line review), while preserving both implementations.

I have not approved this head because the Linux-only behavior has no reported test yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5629816241 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10223#pullrequestreview-5629816241). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T14:37:51Z. **Review:** CHANGES_REQUESTED --- The Windows measurements and focused formatting coverage are useful, and the hosted conventions/relinker/register-context checks pass. Two items still need closing before this is ready for approval: 1. Please run the focused formatting test on Linux against this exact head (including the new `RequiresGuestFormatting` routing for unknown conversions), and report the command/result. The PR description currently says Linux was not run, and hosted Linux/Windows product jobs are skipped. 2. This changes `WindowsFormatting.hpp`'s conversion branch alongside #3987, and the overlap report also lists several in-flight libc math PRs that edit the debt file. The repository checklist asks authors to agree on ordering for overlapping changes. Please coordinate with #3987's author and record the agreed order in `Depends on` (or confirm the changes are independent after the shared-line review), while preserving both implementations. I have not approved this head because the Linux-only behavior has no reported test yet.
MarcZX10 commented 2026-10-23 20:22:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T20:22:35Z.

Review: APPROVED


Reviewed head 4756ead5d75f17ef19ff004e6f9bb2ccb5c7d18a. I checked the formatter and Linux dispatch changes, including size handling, NaN sign/flags, UTF-16-unit encoding, numbered arguments, unknown-conversion formatting, and the corresponding tests/debt note. The author has since reported the focused Linux guest_formatting target passing three times at this exact head, and the PR now records its ordering dependency on #3987. The current hosted conventions, relinker, register-context, and write-watch checks pass; hosted full Linux and Windows product jobs are skipped. I could not start the documented manual full build because GitHub returned HTTP 403 (repository admin rights required). I did not independently rerun the Linux formatter test in this workspace. No blocking issue found in the reviewed diff. AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5634003386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10223#pullrequestreview-5634003386). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T20:22:35Z. **Review:** APPROVED --- Reviewed head `4756ead5d75f17ef19ff004e6f9bb2ccb5c7d18a`. I checked the formatter and Linux dispatch changes, including size handling, NaN sign/flags, UTF-16-unit encoding, numbered arguments, unknown-conversion formatting, and the corresponding tests/debt note. The author has since reported the focused Linux `guest_formatting` target passing three times at this exact head, and the PR now records its ordering dependency on #3987. The current hosted conventions, relinker, register-context, and write-watch checks pass; hosted full Linux and Windows product jobs are skipped. I could not start the documented manual full build because GitHub returned HTTP 403 (repository admin rights required). I did not independently rerun the Linux formatter test in this workspace. No blocking issue found in the reviewed diff. AI-assisted review.
Sign in to join this conversation.
No reviewers
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!10223
No description provided.