fix(libc): bound narrow formatting fields #11332

Closed
Queuse wants to merge 1 commit from upstream-pr/11332 into main
Queuse commented 2026-10-26 03:58:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-26T03:58:01Z.


What

Windows narrow printf can misreport oversized fields or fail while formatting even a valid INT_MAX width into a tiny buffer (#11292). Check field bounds and stream padding and precision zeros while retaining the full output count. Overflow returns -1 with guest EOVERFLOW (84).

Draft for integration coordination: #9087 goes first (confirmed) and is still open. The #9958-first and #11341-first orders are now fulfilled: both are merged. The rebase after #9087 lands must retain deferred termination in Pad, the console long-double mantissa handling and #11341's portable GuestLongDoubleLoad path. #5021 was closed by its author on 2026-11-12. The published head and its tests below remain unchanged while #9087 is pending.

Tested

Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT r7, Ninja Release, BUILD_TESTING=ON. Head 793a55ba18 on main 33ae5a3146.

  • Rebuilt libc and guest_formatting_tests, guest_wide_formatting_tests, guest_stdio_variadic_tests; all three focused CTests pass.
  • Regressions cover literal/star and positional fields, capacities 0/1/16, sentinels, INT_MAX widths and exact-length precisions, cumulative overflow, negative star precision, typed string arguments and finite/nonfinite floating conversions.
  • 32,400 bounded integer cases match Linux libc; 86,400 double and 31,104 long-double cases preserve baseline results (149,904 comparisons, zero differences).
  • Linux WSL actual-source harness: six moderate floating fields pass with individual allocations over 64 KiB refused; five failed that allocation check before the streaming change. The 32,400-case integer comparison also passes with the formatter compiled directly on Linux.
  • Conventions, public-header audit, test registration and whitespace checks pass.

No full product suite, Linux product build, title or physical-console run. Extreme-field console error behavior remains unmeasured and is recorded in debt/libc.md.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: #9087 (merge order confirmed, pending). #9958 and #11341 merged.
  • Fixes: Fixes #11292
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5011789276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11332). Originally posted by [Queuse](https://github.com/Queuse) on 2026-10-26T03:58:01Z. --- ### What Windows narrow printf can misreport oversized fields or fail while formatting even a valid INT_MAX width into a tiny buffer (#11292). Check field bounds and stream padding and precision zeros while retaining the full output count. Overflow returns -1 with guest EOVERFLOW (84). Draft for integration coordination: #9087 goes first ([confirmed](https://github.com/boykopovar/AnyPS5/pull/9087#issuecomment-6407671599)) and is still open. The #9958-first and #11341-first orders are now fulfilled: both are merged. The rebase after #9087 lands must retain deferred termination in Pad, the console long-double mantissa handling and #11341's portable `GuestLongDoubleLoad` path. #5021 was closed by its author on 2026-11-12. The published head and its tests below remain unchanged while #9087 is pending. ### Tested Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT r7, Ninja Release, BUILD_TESTING=ON. Head 793a55ba18 on main 33ae5a3146. - Rebuilt libc and guest_formatting_tests, guest_wide_formatting_tests, guest_stdio_variadic_tests; all three focused CTests pass. - Regressions cover literal/star and positional fields, capacities 0/1/16, sentinels, INT_MAX widths and exact-length precisions, cumulative overflow, negative star precision, typed string arguments and finite/nonfinite floating conversions. - 32,400 bounded integer cases match Linux libc; 86,400 double and 31,104 long-double cases preserve baseline results (149,904 comparisons, zero differences). - Linux WSL actual-source harness: six moderate floating fields pass with individual allocations over 64 KiB refused; five failed that allocation check before the streaming change. The 32,400-case integer comparison also passes with the formatter compiled directly on Linux. - Conventions, public-header audit, test registration and whitespace checks pass. No full product suite, Linux product build, title or physical-console run. Extreme-field console error behavior remains unmeasured and is recorded in debt/libc.md. <!-- 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. --> ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: <!-- #PR, or none --> #9087 (merge order confirmed, pending). #9958 and #11341 merged. - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> Fixes #11292 - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-26 07:22:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T07:22:48Z.

Review: COMMENTED


I inspected the live overlap rather than relying only on the bot table. A two-head git merge-tree preview between this head (793a55ba18) and #11341 (fcb72551ab) conflicts in WindowsFormatting.hpp. #11341 changes FormatArguments::Next<long double> to use GuestLongDoubleLoad and removes the native-long-double layout assertions; this formatter rewrite must preserve that portable long-double path when the two changes are combined. Please coordinate the order with #11341’s author and record the dependency/order in the checklist. The #9958-first / #5021-after order is still marked pending in this draft, so keep it explicit as those authors confirm it; I am not asking anyone to close a PR.

The branch is also 1 ahead and 92 behind current main (fdb3925940), with a clean merge preview but docs/dev/debt/libc.md changed on both sides since the base. CONTRIBUTING says to keep branches current; please rebase after the stack order is settled, preserve the overlapping debt edits, and rerun the focused Windows formatters and local overlap/convention checks on that exact head. I am not approving this draft before those integration and current-head checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648635013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11332#pullrequestreview-5648635013). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T07:22:48Z. **Review:** COMMENTED --- I inspected the live overlap rather than relying only on the bot table. A two-head `git merge-tree` preview between this head (`793a55ba18`) and #11341 (`fcb72551ab`) conflicts in `WindowsFormatting.hpp`. #11341 changes `FormatArguments::Next<long double>` to use `GuestLongDoubleLoad` and removes the native-long-double layout assertions; this formatter rewrite must preserve that portable long-double path when the two changes are combined. Please coordinate the order with #11341’s author and record the dependency/order in the checklist. The #9958-first / #5021-after order is still marked pending in this draft, so keep it explicit as those authors confirm it; I am not asking anyone to close a PR. The branch is also 1 ahead and 92 behind current `main` (`fdb3925940`), with a clean merge preview but `docs/dev/debt/libc.md` changed on both sides since the base. CONTRIBUTING says to keep branches current; please rebase after the stack order is settled, preserve the overlapping debt edits, and rerun the focused Windows formatters and local overlap/convention checks on that exact head. I am not approving this draft before those integration and current-head checks.

Pull request closed

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!11332
No description provided.