fix(libc): ignore non-wide lengths on character scans #13049

Merged
JJenkx merged 1 commit from upstream-pr/13049 into main 2026-10-30 15:25:56 +00:00
JJenkx commented 2026-10-29 23:40:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-29T23:40:49Z.


What

A character field such as %lls in the title-bundled libc modules stores narrow bytes. Forwarding it to glibc can instead store 32-bit wide characters. The same discrepancy affects ignored length tokens on %c and %[ fields.

Normalize accepted non-wide lengths in host-backed character scans and in the secure scanner's generated directives. Preserve a single l, numeric lengths, widths/suppression, literal %% and scanset members. Regression cases check consumed bytes and destination guards through ordinary, secure and va-list string/file APIs.

Related work: #12428 supplies the Windows ordinary-parser length rule; #12468 supplies wide-field recognition/decoding. This implementation complements those paths. The new Windows cases exercise the secure paths changed here; the new Linux cases exercise all eight entry points.

Tested

Linux x86-64 Release, exact production/test source ce32d855ba3817332ab44e454f95f6257836943d, based on main 7a225bb303c1a452057000f32b70b56486625fd6. Clean merge preview against subsequently fetched main 1189ec3003672bb364dd9f3119ead7b3976e3c83; public branches of related PRs were preserved.

cmake --build build --parallel 2 --target libc guest_formatting_tests guest_wide_formatting_tests guest_safe_error_tests file_streams_tests
ctest --test-dir build -V -R '^(guest_formatting|guest_wide_formatting|guest_safe_errors|file_streams)$'
  • Actual libc builds and 4/4 focused suites pass on both main and the change, zero skips.
  • Both new guest_formatting_tests and file_streams_tests executables fail against coherent unmodified base libraries with the expected character-scan length failures. Restored candidate library bytes match the module used for reference comparison.
  • CPU-only reference calls into two bundled libc modules (PPSA03766 and PPSA07923), using separate processes and private temporary streams. They agree on all 4,968 rows. String cases vary nine lengths, five conversions, widths, suppression and inputs; stream cases cover eight non-wide lengths and three conversions. Observed fields include return, errno, destination prefix and constraint-handler activity.
Reference matrix Rows/library Main mismatches Change mismatches Full rows corrected
sscanf / sscanf_s 3240 1048 698 350
fscanf / fscanf_s 1728 478 128 350

700 full rows corrected; zero regressions in previously correct observed fields. Twenty further destination-prefix fields become correct while an existing short-field return mismatch remains. Existing EOF errno, wide/uppercase-conversion and short-character gaps remain explicit. The short-character gap is recorded in debt. This is not complete scanf coverage.

Authored probes, synthetic reference/main/change rows, positive/negative logs, source pins and hashes, SHA-256 7fceb0465f933407de4eab5d866804a957185ac902f1c8d32c483894d30cf233 (download verified). No SDK binaries, game assets, saves or screenshots are included.

Conventions/whitespace pass. Required overlap scan checked 1431 open PRs with no automatic positive overlap. Shared-file diffs of peers already conflicting with main were reviewed; their classifications are attached. No blanket peer-mergeability claim.

Windows/macOS execution is not locally qualified. Windows ordinary scans use the separate parser covered by #12428; this PR's Windows regression cases cover its four secure entry points. No console, title, graphics, audio or FPS claim.

Independent Windows validation, reported by bunbeans2-arch for topic ce32d855ba3817332ab44e454f95f6257836943d against main f7f03daf52: Windows 11 Pro 22631, i9-9900K, MSYS2 UCRT64 GCC 16.1, Release. file_streams and guest_formatting pass 5/5; keeping the new tests while restoring Formatting.cpp to main makes both fail 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: none
  • Fixes: none
  • Unblocks: none; library correctness
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5077146115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13049). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-29T23:40:49Z. --- ### What A character field such as `%lls` in the title-bundled libc modules stores narrow bytes. Forwarding it to glibc can instead store 32-bit wide characters. The same discrepancy affects ignored length tokens on `%c` and `%[` fields. Normalize accepted non-wide lengths in host-backed character scans and in the secure scanner's generated directives. Preserve a single `l`, numeric lengths, widths/suppression, literal `%%` and scanset members. Regression cases check consumed bytes and destination guards through ordinary, secure and va-list string/file APIs. Related work: #12428 supplies the Windows ordinary-parser length rule; #12468 supplies wide-field recognition/decoding. This implementation complements those paths. The new Windows cases exercise the secure paths changed here; the new Linux cases exercise all eight entry points. ### Tested Linux x86-64 Release, exact production/test source `ce32d855ba3817332ab44e454f95f6257836943d`, based on main `7a225bb303c1a452057000f32b70b56486625fd6`. Clean merge preview against subsequently fetched main `1189ec3003672bb364dd9f3119ead7b3976e3c83`; public branches of related PRs were preserved. ```sh cmake --build build --parallel 2 --target libc guest_formatting_tests guest_wide_formatting_tests guest_safe_error_tests file_streams_tests ctest --test-dir build -V -R '^(guest_formatting|guest_wide_formatting|guest_safe_errors|file_streams)$' ``` - Actual libc builds and **4/4 focused suites pass on both main and the change**, zero skips. - Both new `guest_formatting_tests` and `file_streams_tests` executables fail against coherent unmodified base libraries with the expected character-scan length failures. Restored candidate library bytes match the module used for reference comparison. - CPU-only reference calls into two bundled libc modules (PPSA03766 and PPSA07923), using separate processes and private temporary streams. They agree on all **4,968 rows**. String cases vary nine lengths, five conversions, widths, suppression and inputs; stream cases cover eight non-wide lengths and three conversions. Observed fields include return, errno, destination prefix and constraint-handler activity. | Reference matrix | Rows/library | Main mismatches | Change mismatches | Full rows corrected | |---|---:|---:|---:|---:| | `sscanf` / `sscanf_s` |3240|1048|698|350| | `fscanf` / `fscanf_s` |1728|478|128|350| **700 full rows corrected; zero regressions in previously correct observed fields.** Twenty further destination-prefix fields become correct while an existing short-field return mismatch remains. Existing EOF errno, wide/uppercase-conversion and short-character gaps remain explicit. The short-character gap is recorded in debt. This is not complete scanf coverage. [Authored probes, synthetic reference/main/change rows, positive/negative logs, source pins and hashes](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/libc-character-scan-lengths-linux-20261029.tar.gz), SHA-256 `7fceb0465f933407de4eab5d866804a957185ac902f1c8d32c483894d30cf233` (download verified). No SDK binaries, game assets, saves or screenshots are included. Conventions/whitespace pass. Required overlap scan checked **1431 open PRs** with no automatic positive overlap. Shared-file diffs of peers already conflicting with main were reviewed; their classifications are attached. No blanket peer-mergeability claim. Windows/macOS execution is not locally qualified. Windows ordinary scans use the separate parser covered by #12428; this PR's Windows regression cases cover its four secure entry points. No console, title, graphics, audio or FPS claim. <!-- 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. --> Independent Windows validation, reported by [bunbeans2-arch](https://github.com/boykopovar/AnyPS5/pull/13049#issuecomment-6517132103) for topic `ce32d855ba3817332ab44e454f95f6257836943d` against main `f7f03daf52`: Windows 11 Pro 22631, i9-9900K, MSYS2 UCRT64 GCC 16.1, Release. `file_streams` and `guest_formatting` pass 5/5; keeping the new tests while restoring `Formatting.cpp` to main makes both fail 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: <!-- #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; library correctness - [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-30 00:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T00:09:09Z.

Review: APPROVED


Reviewed — looks good

The change normalizes ignored narrow-character scan lengths while preserving the single-l wide path, with regression coverage across string, stream, secure, and va-list entry points.

What I ran

Reviewed exact head ce32d855ba3817332ab44e454f95f6257836943d against current main e7d8e353362935a1f00e893d901b1debc671f5ce; the clean merge-preview tree is 6715ec4f2bcc30b5f5733ddbe0aa744f15f1fed1. Environment: Debian Linux x86-64, Python 3.11.2; no compiler or build was run.

git merge-tree --write-tree upstream/main refs/review/pr-13049-current
git diff --check upstream/main...refs/review/pr-13049-current
python3 tools/check_conventions.py --base upstream/main --head refs/review/pr-13049-current
  • The changed source, tests, call paths, and current CI were inspected. Conventions and whitespace checks passed.
  • The PR body records author-run focused validation and its limitations; I did not independently rerun build-dependent tests.

Not verified

I did not build or run the C++ tests locally, and I did not verify physical-console or game behavior. Some hosted platform matrix jobs were still running or queued at review time.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5706563188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13049#pullrequestreview-5706563188). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T00:09:09Z. **Review:** APPROVED --- # Reviewed — looks good The change normalizes ignored narrow-character scan lengths while preserving the single-`l` wide path, with regression coverage across string, stream, secure, and va-list entry points. ## What I ran Reviewed exact head `ce32d855ba3817332ab44e454f95f6257836943d` against current `main` `e7d8e353362935a1f00e893d901b1debc671f5ce`; the clean merge-preview tree is `6715ec4f2bcc30b5f5733ddbe0aa744f15f1fed1`. Environment: Debian Linux x86-64, Python 3.11.2; no compiler or build was run. ```sh git merge-tree --write-tree upstream/main refs/review/pr-13049-current git diff --check upstream/main...refs/review/pr-13049-current python3 tools/check_conventions.py --base upstream/main --head refs/review/pr-13049-current ``` - The changed source, tests, call paths, and current CI were inspected. Conventions and whitespace checks passed. - The PR body records author-run focused validation and its limitations; I did not independently rerun build-dependent tests. ## Not verified I did not build or run the C++ tests locally, and I did not verify physical-console or game behavior. Some hosted platform matrix jobs were still running or queued at review time.
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!13049
No description provided.