fix(libc): match bundled narrow scansets and scan directive parsing #12428

Merged
JJenkx merged 8 commits from upstream-pr/12428 into main 2026-11-02 17:27:00 +00:00
JJenkx commented 2026-10-28 13:23:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T13:23:03Z.


What

The narrow scanf paths now follow the bundled libraries' scanset, length and termination rules. Windows scansets are translated into explicit byte lists rather than inheriting the host's range rules, and string/character/scanset conversions retain only a bare l length.

The shared secure/stream scanner reads one length letter or hh/ll, matching the Windows translator. Thus %hls stops at the unknown conversion instead of accepting the whole length run and writing a narrow string through one entry point. A bare %ls still writes UTF-16.

Unknown conversions stop the shared scanner as a matching failure before it checks for input EOF. Incomplete Windows directives such as %l likewise end the scan without setting EINVAL. Regression rows cover malformed lengths, empty input, %5y, %k, and %ls through both plain and secure entry points.

Linux's remaining host string-length/EOF-errno differences and plain q extension are recorded in the debt file. The shared secure q directive now ends without storing, as the reference modules do.

Tested

Exact follow-up head 4faeb3255c0d36d91503dd41b0d04b9dd8f67cef; qualification is of this PR branch, not a latest-main integration. Current-main rebase remains separate pending work.

  • Actual Linux/Arch (Ryzen7950X, GCC16.2.1, glibc2.44) and Windows11 Enterprise22621 (Ryzen5950X, WinLibs GCC15.2.0 UCRT r7), Release: guest_formatting, guest_wide_formatting, guest_safe_errors, guest_stdio_variadic, guest_scan_count, guest_wide_stream_scan, each repeated3: 18 focused executions per host.
  • Converted owned PPSA03766 and PPSA07923 SDK references agree on 88 cases each across sscanf/sscanf_s, including stored bytes/canaries, return count, errno and constraint-handler observations. Final actual Windows library matches all88 against both references without normalization.
  • Linux comparison improves 19 differences to8 over those88 cases:11 corrected, no previously matching case regresses. The retained glibc narrow-length and EOF-errno cases are documented rather than counted as matches.
  • Actual Windows-library negative controls reject the published source parser, published incomplete-directive header, and a bare-l drop mutant. Original source is restored, Git is clean, and all9 formatting/error executions pass again. Additional stream/count/variadic groups then pass9 more executions.
  • Restoring the previous Linux ScanSource fails the new regression. Restoring the final source passes9 formatting/error executions again; the additional stream groups also pass9. Supplemental %qd rows confirm secure matching failure and the retained plain-Linux extension.

Raw observations, probes, reference identities, both-host build/test logs and JUnit, source patch and mutation controls, SHA-256 d7880e3dbed6b5f28a4536973b6da8e2f8a5e6525f504c096bf5b91b4b2f284b (download verified). References execute as converted modules on Linux, not a console. macOS, other SDKs/locales and native-title effects remain unverified. No FPS claim.

Original scanset qualification (earlier-head evidence; its100,000-case replay was not repeated in this follow-up):

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, on main 750cf6cf48.

  • Against titles' own libc.prx: I loaded PPSA07923's and PPSA05916's libc.prx natively and called their sscanf (1Pk0qZQGeWo) and sscanf_s (24m4Z4bUaoY) side by side with this build. I compared the return value, the bytes stored and %n:
    • 49 hand-picked pairs: 0 differences.

    • 100,000 random scansets each for sscanf and sscanf_s, built from abcz-]^* and the bytes 0x80/0xFF (sometimes negated), with random inputs:

      sscanf sscanf_s
      main 3,040 1,602
      this branch 2 2
    • The 2 left both have a byte ≥ 0x80 as a literal in the format after the set. The titles fail that literal match and the host makes it. It's listed in the debt entry, not fixed here.

  • Tests: guest_formatting (16 new rows, each through sscanf and sscanf_s), guest_stdio_variadic, guest_scan_count and guest_wide_stream_scan pass in each of 3 runs.
  • Negative control: with main's WindowsScanning.hpp and Formatting.cpp, guest_formatting fails.

Current Linux qualification — 2026-10-29

Integrated current main 157b02c4f1803e9d2cd757677b9a805961203fc4 by normal fast-forward merge; earlier measured fixes, tests and actual parent ancestry are retained.

New head: efdeef66aa35be7ef17c73152ac2dddac6ea18da. The source and tests merge automatically. The debt resolution keeps the measured narrow-scanset entry and main’s updated quad-length behavior, replacing the stale Linux-as-ll description.

Linux Release: guest_formatting, guest_wide_formatting, guest_stdio_variadic, guest_scan_count, guest_wide_stream_scan pass three repetitions (15 checks), plus the public-header audit, zero skips. Actual Formatting.cpp and FormattingWide.cpp, including WindowsFormatting.hpp, pass MinGW GCC16.2.0 cross syntax checking. Conventions report zero errors; any debt-length warnings are preserved in the logs. Whitespace and recursive submodule-pointer checks pass.

This is current-main Linux integration and Windows cross-compilation syntax evidence. Earlier actual Windows/title-library measurements retain their historical pins; no new Windows runtime, macOS, title, GPU or performance result is claimed. AI-assisted: yes.

Evidence: immutable Linux qualification bundle. Its SHA-256 is ca6b35926bcc6d3f21a9650517894c86b65594e2e2b653c5c32cd1c1de89c835. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.

AI-assisted: yes (Codex).

Independent Windows validation, reported by bunbeans2-arch for topic efdeef66aa35be7ef17c73152ac2dddac6ea18da against main f7f03daf52: Windows 11 Pro 22631, i9-9900K, MSYS2 UCRT64 GCC 16.1, Release. guest_formatting passes 5/5; retaining the new test while restoring Formatting.cpp and WindowsScanning.hpp to main fails 5/5; plain main passes 3/3. This is the contributor's run, not a new local Windows execution.

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: #9087 (agreed to land first); #11852 is now merged and included in this current-main integration
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code and Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5051204052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12428). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T13:23:03Z. --- ### What The narrow scanf paths now follow the bundled libraries' scanset, length and termination rules. Windows scansets are translated into explicit byte lists rather than inheriting the host's range rules, and string/character/scanset conversions retain only a bare `l` length. The shared secure/stream scanner reads one length letter or `hh`/`ll`, matching the Windows translator. Thus `%hls` stops at the unknown conversion instead of accepting the whole length run and writing a narrow string through one entry point. A bare `%ls` still writes UTF-16. Unknown conversions stop the shared scanner as a matching failure before it checks for input EOF. Incomplete Windows directives such as `%l` likewise end the scan without setting EINVAL. Regression rows cover malformed lengths, empty input, `%5y`, `%k`, and `%ls` through both plain and secure entry points. Linux's remaining host string-length/EOF-errno differences and plain `q` extension are recorded in the debt file. The shared secure `q` directive now ends without storing, as the reference modules do. ### Tested Exact follow-up head `4faeb3255c0d36d91503dd41b0d04b9dd8f67cef`; qualification is of this PR branch, not a latest-main integration. Current-main rebase remains separate pending work. - Actual Linux/Arch (Ryzen7950X, GCC16.2.1, glibc2.44) and Windows11 Enterprise22621 (Ryzen5950X, WinLibs GCC15.2.0 UCRT r7), Release: `guest_formatting`, `guest_wide_formatting`, `guest_safe_errors`, `guest_stdio_variadic`, `guest_scan_count`, `guest_wide_stream_scan`, each repeated3: **18 focused executions per host**. - Converted owned PPSA03766 and PPSA07923 SDK references agree on **88 cases each** across `sscanf`/`sscanf_s`, including stored bytes/canaries, return count, errno and constraint-handler observations. Final actual Windows library matches all88 against both references without normalization. - Linux comparison improves **19 differences to8** over those88 cases:11 corrected, no previously matching case regresses. The retained glibc narrow-length and EOF-errno cases are documented rather than counted as matches. - Actual Windows-library negative controls reject the published source parser, published incomplete-directive header, and a bare-`l` drop mutant. Original source is restored, Git is clean, and all9 formatting/error executions pass again. Additional stream/count/variadic groups then pass9 more executions. - Restoring the previous Linux `ScanSource` fails the new regression. Restoring the final source passes9 formatting/error executions again; the additional stream groups also pass9. Supplemental `%qd` rows confirm secure matching failure and the retained plain-Linux extension. [Raw observations, probes, reference identities, both-host build/test logs and JUnit, source patch and mutation controls](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-scan-parser-linux-windows-20261029-r2.tar.gz), SHA-256 `d7880e3dbed6b5f28a4536973b6da8e2f8a5e6525f504c096bf5b91b4b2f284b` (download verified). References execute as converted modules on Linux, not a console. macOS, other SDKs/locales and native-title effects remain unverified. No FPS claim. **Original scanset qualification (earlier-head evidence; its100,000-case replay was not repeated in this follow-up):** Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`, on `main` `750cf6cf48`. - **Against titles' own `libc.prx`:** I loaded PPSA07923's and PPSA05916's `libc.prx` natively and called their `sscanf` (`1Pk0qZQGeWo`) and `sscanf_s` (`24m4Z4bUaoY`) side by side with this build. I compared the return value, the bytes stored and `%n`: - **49 hand-picked pairs:** 0 differences. - **100,000 random scansets** each for `sscanf` and `sscanf_s`, built from `abcz-]^*` and the bytes 0x80/0xFF (sometimes negated), with random inputs: | | `sscanf` | `sscanf_s` | |---|---|---| | `main` | 3,040 | 1,602 | | this branch | 2 | 2 | - **The 2 left** both have a byte ≥ 0x80 as a literal in the format after the set. The titles fail that literal match and the host makes it. It's listed in the debt entry, not fixed here. - **Tests:** `guest_formatting` (16 new rows, each through `sscanf` and `sscanf_s`), `guest_stdio_variadic`, `guest_scan_count` and `guest_wide_stream_scan` pass in each of 3 runs. - **Negative control:** with `main`'s `WindowsScanning.hpp` and `Formatting.cpp`, `guest_formatting` fails. <!-- codex-maintenance-20261029-repeat-12428 --> **Current Linux qualification — 2026-10-29** Integrated current `main` `157b02c4f1803e9d2cd757677b9a805961203fc4` by normal fast-forward merge; earlier measured fixes, tests and actual parent ancestry are retained. New head: `efdeef66aa35be7ef17c73152ac2dddac6ea18da`. The source and tests merge automatically. The debt resolution keeps the measured narrow-scanset entry and main’s updated quad-length behavior, replacing the stale Linux-as-ll description. Linux Release: `guest_formatting`, `guest_wide_formatting`, `guest_stdio_variadic`, `guest_scan_count`, `guest_wide_stream_scan` pass three repetitions (15 checks), plus the public-header audit, zero skips. Actual `Formatting.cpp` and `FormattingWide.cpp`, including `WindowsFormatting.hpp`, pass MinGW GCC16.2.0 cross syntax checking. Conventions report zero errors; any debt-length warnings are preserved in the logs. Whitespace and recursive submodule-pointer checks pass. This is current-main Linux integration and Windows cross-compilation syntax evidence. Earlier actual Windows/title-library measurements retain their historical pins; no new Windows runtime, macOS, title, GPU or performance result is claimed. AI-assisted: yes. Evidence: [immutable Linux qualification bundle](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/cpu-complete-current-main-linux-20261029.tar.gz). Its SHA-256 is `ca6b35926bcc6d3f21a9650517894c86b65594e2e2b653c5c32cd1c1de89c835`. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins. AI-assisted: yes (Codex). Independent Windows validation, reported by [bunbeans2-arch](https://github.com/boykopovar/AnyPS5/pull/12428#issuecomment-6518265409) for topic `efdeef66aa35be7ef17c73152ac2dddac6ea18da` against main `f7f03daf52`: Windows 11 Pro 22631, i9-9900K, MSYS2 UCRT64 GCC 16.1, Release. `guest_formatting` passes 5/5; retaining the new test while restoring `Formatting.cpp` and `WindowsScanning.hpp` to main fails 5/5; plain main passes 3/3. This is the contributor's run, not a new local Windows execution. ### 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: #9087 (agreed to land first); #11852 is now merged and included in this current-main integration - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code and Codex)
MarcZX10 commented 2026-10-28 13:52:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T13:52:21Z.

Review: CHANGES_REQUESTED


The code and test evidence are substantial, and I found no concrete implementation defect in the reviewed diff. The merge-order coordination is also now clear in the threads: #9087's author agreed it lands first, and #11852's author agreed it lands first and described the rebase placement needed afterward.

One repository checklist item still conflicts with that agreement. CONTRIBUTING.md says to declare a required PR on the checklist line as Depends on: #N; the current line says Depends on: none while the body says #9087 and #11852 should land first. Please change the checklist to list both prerequisites so the recorded merge order matches the agreement. I am requesting this metadata correction only; no code correctness blocker is identified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5683737862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12428#pullrequestreview-5683737862). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T13:52:21Z. **Review:** CHANGES_REQUESTED --- The code and test evidence are substantial, and I found no concrete implementation defect in the reviewed diff. The merge-order coordination is also now clear in the threads: #9087's author agreed it lands first, and #11852's author agreed it lands first and described the rebase placement needed afterward. One repository checklist item still conflicts with that agreement. `CONTRIBUTING.md` says to declare a required PR on the checklist line as `Depends on: #N`; the current line says `Depends on: none` while the body says #9087 and #11852 should land first. Please change the checklist to list both prerequisites so the recorded merge order matches the agreement. I am requesting this metadata correction only; no code correctness blocker is identified.
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!12428
No description provided.