fix(libc): retain short wide scanf character fields #9863

Merged
UnhealthyKraken merged 16 commits from upstream-pr/9863 into main 2026-11-04 03:58:43 +00:00
UnhealthyKraken commented 2026-10-22 19:38:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T19:38:19Z.


What

Keep a nonempty character field when wide scanf reaches EOF before its requested width. Input a with %3lc returns one assignment, stores only a without a terminator, and continues to %n or a following directive. Suppression consumes the prefix without adding an assignment; an empty field remains an input failure. Positive-capacity secure wide destinations consume at most min(width, capacity). For positive-length input, a zero-capacity wide destination adds no assignment, leaves output/errno unchanged and stops before the following %n.

Short-field behavior follows pinned FreeBSD11.4 convert_char/convert_wchar, supplemented by hypermoist's report and JJenkx's native calls to three bundled libraries. These are attributed contributor measurements, not my console measurements or firmware-wide proof. Zero-capacity consumption/empty-input precedence, narrow byte-capacity rules and native stream parity remain unverified in debt. The reported undersized narrow ASCII case remains a known gap; no test pins its unsupported exception behavior.

The review refresh retains main's public declarations, UTF-8 and %S/%C matching-failure behavior and one combined scanner debt bullet. Blazing Cook's positive-capacity contribution retains its author identity/history. The agreed order remains #9863 before #9087; names, NIDs and implemented ABI do not change.

Tested

Review revision 5f290cecde56468bb507d4c72b9de50c03eeab87, based on main 47f9cee2cd77 by history-preserving merge.

Hosted Linux actual project configure/focused build passed with matching source-built libraries: both scanner suites pass once plus five repetitions each. Conventions (0 errors; existing combined debt-length warning), whitespace, public-header audit and standalone libc/kernel header compilation pass. Linux job. Windows final-head actual project configure/affected-target build passed on hosted WinLibs GCC 15.2 Release with matching runtime libraries: 2/2 focused tests, followed by two repetitions each. Windows job. Git-only mergeability against later fetched main 504ea3b53b23 is clean; that later combined tree was not built.

Original Windows baseline/candidate and later independent contributor results remain recorded in the earlier review report and zero-capacity correction; those are historical heads, not additional final-head platform runs.

No local builds/runtime tests, games, proprietary modules or physical-console execution were performed for this revision. The full repository suite was not run.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4973076586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9863). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T19:38:19Z. --- ### What Keep a nonempty character field when wide scanf reaches EOF before its requested width. Input `a` with `%3lc` returns one assignment, stores only `a` without a terminator, and continues to `%n` or a following directive. Suppression consumes the prefix without adding an assignment; an empty field remains an input failure. Positive-capacity secure wide destinations consume at most `min(width, capacity)`. For positive-length input, a zero-capacity wide destination adds no assignment, leaves output/errno unchanged and stops before the following `%n`. Short-field behavior follows pinned FreeBSD11.4 [convert_char/convert_wchar](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/libc/stdio/vfwscanf.c#L140-L179), supplemented by [hypermoist's report](https://github.com/boykopovar/AnyPS5/issues/9321#issuecomment-6342217421) and [JJenkx's native calls to three bundled libraries](https://github.com/boykopovar/AnyPS5/pull/9863#issuecomment-6357861510). These are attributed contributor measurements, not my console measurements or firmware-wide proof. Zero-capacity consumption/empty-input precedence, narrow byte-capacity rules and native stream parity remain unverified in debt. The reported undersized narrow ASCII case remains a known gap; no test pins its unsupported exception behavior. The review refresh retains main's public declarations, UTF-8 and `%S`/`%C` matching-failure behavior and one combined scanner debt bullet. Blazing Cook's positive-capacity contribution retains its author identity/history. The agreed order remains #9863 before #9087; names, NIDs and implemented ABI do not change. ### Tested Review revision `5f290cecde56468bb507d4c72b9de50c03eeab87`, based on main `47f9cee2cd77` by history-preserving merge. Hosted Linux actual project configure/focused build passed with matching source-built libraries: both scanner suites pass once plus five repetitions each. Conventions (0 errors; existing combined debt-length warning), whitespace, public-header audit and standalone libc/kernel header compilation pass. [Linux job](https://github.com/UnhealthyKraken/AnyPS5/actions/runs/40251248364/job/121343419586). Windows final-head actual project configure/affected-target build passed on hosted WinLibs GCC 15.2 Release with matching runtime libraries: 2/2 focused tests, followed by two repetitions each. [Windows job](https://github.com/UnhealthyKraken/AnyPS5/actions/runs/40251248364/job/121349451462). Git-only mergeability against later fetched main `504ea3b53b23` is clean; that later combined tree was not built. Original Windows baseline/candidate and later independent contributor results remain recorded in the [earlier review report](https://github.com/boykopovar/AnyPS5/pull/9863#issuecomment-6366169118) and [zero-capacity correction](https://github.com/boykopovar/AnyPS5/pull/9863#issuecomment-6367557023); those are historical heads, not additional final-head platform runs. No local builds/runtime tests, games, proprietary modules or physical-console execution were performed for this revision. The full repository suite was not run. <!-- 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) - [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 --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [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-22 20:15:54 +00:00 (Migrated from github.com)

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

Review: COMMENTED


I reviewed the implementation path and the added regressions against the contributor-reported bundled-library table in #9321. The code now assigns the consumed nonempty %c/%lc prefix without a terminator, continues to later directives and %n, and leaves suppressed fields unassigned. Tests cover both string and stream scanners, secure/unsecure entry points, prior assignments, exact canary bounds, lookahead and an explicitly unsupported undersized secure-capacity case. The debt text keeps the evidence attribution and remaining limits clear. The coordinated order with #9087 is documented by both authors, and Depends on: none is consistent with the confirmed independent order.

The author reports Windows focused builds/runs and 8/8 candidate suites (9/9 including loader) against identical executables, plus 1177 test registrations. Hosted conventions, relinker and registration checks pass; hosted Linux/Windows product jobs are skipped. I did not independently run the Windows binaries here.

One freshness item: current upstream main is a0900b9d; GitHub compare reports head 26db0f2a is two commits ahead and 26 behind, with merge base d6e7ab42. CONTRIBUTING asks branches to stay current. Please rebase, preserve the agreed #9087 wording/order, and rerun the two focused scanner suites plus conventions on the final combined head before merge. No blocking behavior defect found in the reviewed diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5620284733 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9863#pullrequestreview-5620284733). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T20:15:54Z. **Review:** COMMENTED --- I reviewed the implementation path and the added regressions against the contributor-reported bundled-library table in #9321. The code now assigns the consumed nonempty `%c`/`%lc` prefix without a terminator, continues to later directives and `%n`, and leaves suppressed fields unassigned. Tests cover both string and stream scanners, secure/unsecure entry points, prior assignments, exact canary bounds, lookahead and an explicitly unsupported undersized secure-capacity case. The debt text keeps the evidence attribution and remaining limits clear. The coordinated order with #9087 is documented by both authors, and `Depends on: none` is consistent with the confirmed independent order. The author reports Windows focused builds/runs and 8/8 candidate suites (9/9 including loader) against identical executables, plus 1177 test registrations. Hosted conventions, relinker and registration checks pass; hosted Linux/Windows product jobs are skipped. I did not independently run the Windows binaries here. One freshness item: current upstream `main` is `a0900b9d`; GitHub compare reports head `26db0f2a` is two commits ahead and 26 behind, with merge base `d6e7ab42`. CONTRIBUTING asks branches to stay current. Please rebase, preserve the agreed #9087 wording/order, and rerun the two focused scanner suites plus conventions on the final combined head before merge. No blocking behavior defect found in the reviewed diff.
MarcZX10 commented 2026-10-23 14:18:33 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


I reviewed exact head 12446569274e168eb8e14d2bc86205b7e2d02492.

One measured secure-field case is still represented as an exception, although the linked native-library results report a return value:

  • ScanningWide.cpp:432-433 throws when %3lc has a positive-length short input and capacity zero. GuestWideConversion.cpp:259-264 codifies that as an expected throw.
  • JJenkx's attributed report in the linked native calls says that, for three bundled libc.prx builds, swscanf_s(L"a", L"%3lc%n", w, 0, &n) returns 0, leaves the destination untouched, leaves errno at zero, and does not reach %n. The report explicitly leaves input consumption unknown.

Please make the zero-capacity short-field return and destination behavior match that evidence, and add a regression that checks those observed results without asserting stream/input consumption. Keep consumption marked unverified until measured. The current explicit throw is a known behavior mismatch, even though the cursor position is unknown.

The exact-head report records strong Linux validation (10/10 focused suites, including five repeat runs); I did not rerun those tests locally. Current hosted Linux and Windows product jobs are skipped, while conventions, eligibility, registration, relinker matrix and other applicable checks pass. The PR is also 8 commits behind current main (e94545a5, merge base 938812df); the merge is clean, and those intervening main commits do not touch the four changed files. Please refresh to current main and rerun both focused scanner suites and conventions before merge, as required by the contribution rules.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5629541812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9863#pullrequestreview-5629541812). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T14:18:33Z. **Review:** CHANGES_REQUESTED --- I reviewed exact head `12446569274e168eb8e14d2bc86205b7e2d02492`. One measured secure-field case is still represented as an exception, although the linked native-library results report a return value: - `ScanningWide.cpp:432-433` throws when `%3lc` has a positive-length short input and capacity zero. `GuestWideConversion.cpp:259-264` codifies that as an expected throw. - JJenkx's attributed report in [the linked native calls](https://github.com/boykopovar/AnyPS5/pull/9863#issuecomment-6357861510) says that, for three bundled `libc.prx` builds, `swscanf_s(L"a", L"%3lc%n", w, 0, &n)` returns `0`, leaves the destination untouched, leaves `errno` at zero, and does not reach `%n`. The report explicitly leaves input consumption unknown. Please make the zero-capacity short-field return and destination behavior match that evidence, and add a regression that checks those observed results without asserting stream/input consumption. Keep consumption marked unverified until measured. The current explicit throw is a known behavior mismatch, even though the cursor position is unknown. The exact-head report records strong Linux validation (10/10 focused suites, including five repeat runs); I did not rerun those tests locally. Current hosted Linux and Windows product jobs are skipped, while conventions, eligibility, registration, relinker matrix and other applicable checks pass. The PR is also 8 commits behind current `main` (`e94545a5`, merge base `938812df`); the merge is clean, and those intervening main commits do not touch the four changed files. Please refresh to current `main` and rerun both focused scanner suites and conventions before merge, as required by the contribution rules.
MarcZX10 commented 2026-10-29 06:18:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:18:35Z.

Review: CHANGES_REQUESTED


Re-checked — changes requested

The zero-capacity short-field finding from my earlier review is resolved: the tests now pin the measured assignment count/output/errno behavior, the stale debt sentence is removed, and the author reports focused Linux and Windows runs on the current feature head. I found no new implementation defect in that fix.

Two readiness items remain. First, the #12420 author proposed #9863 first, and the #12514 author independently proposed the same order for the debt-file overlap. Please confirm that order so the follow-up authors can record their dependencies. Second, current main has advanced since this branch’s last merge; docs/dev/debt/libc.md changed on both sides, even though the merge preview is currently clean. Please reconcile the debt entry against current main and rerun the documented checks on the integrated head.

The focused scanner tests and policy checks are reported green; I did not run them locally. This request is for the unconfirmed overlap order and current-main integration, not the resolved zero-capacity behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693635234 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9863#pullrequestreview-5693635234). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T06:18:35Z. **Review:** CHANGES_REQUESTED --- ## Re-checked — changes requested The zero-capacity short-field finding from my earlier review is resolved: the tests now pin the measured assignment count/output/`errno` behavior, the stale debt sentence is removed, and the author reports focused Linux and Windows runs on the current feature head. I found no new implementation defect in that fix. Two readiness items remain. First, the #12420 author proposed #9863 first, and the #12514 author independently proposed the same order for the debt-file overlap. Please confirm that order so the follow-up authors can record their dependencies. Second, current `main` has advanced since this branch’s last merge; `docs/dev/debt/libc.md` changed on both sides, even though the merge preview is currently clean. Please reconcile the debt entry against current main and rerun the documented checks on the integrated head. The focused scanner tests and policy checks are reported green; I did not run them locally. This request is for the unconfirmed overlap order and current-main integration, not the resolved zero-capacity behavior.
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!9863
No description provided.