fix(libc): retain suppressed scanf conversions before EOF #4966

Closed
Dripl1x wants to merge 1 commit from upstream-pr/4966 into main
Dripl1x commented 2026-10-13 06:42:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T06:42:16Z.


What

Linux host scanf can return EOF after a successful assignment-suppressed conversion: sscanf("12", "%*d%d", &value) returns EOF although input was already converted. Return 0 in that case, matching the existing Windows path and FreeBSD's conversion-count handling.

Instrument suppressed input conversions with internal count destinations and forward all destinations through the existing SysV argument representation. The host scanner still reads the input once, including non-seekable streams. Keep true EOF before an input conversion, assignment counts, caller va_list, positional destinations, scansets and the existing pre-C23 %i behavior. Formats without suppression retain the direct host path. Existing unsupported guest-wide conversions remain rejected.

Related: #4815 changes Windows integer widths in WindowsScanning.hpp and its formatting test. This PR changes the Linux path and adds a separate suppression test; it does not depend on that PR and does not modify its files.

Related: #5285 and #5291 replace the same Linux call sites in Formatting.cpp to scan 16-bit wide conversions. The changes are independent and neither builds on the other; a trial merge conflicts only on those lines and keeping both sides resolves it. Order agreed with their author: this PR goes first, and #5285 and #5291 rebase onto it and list it as their dependency (proposal and resolution, agreement).

Tested

Windows, supported WinLibs MinGW-w64 GCC 15.2.0; Linux, Ubuntu 26.04 under WSL, GCC 15.2.0. Release, BUILD_TESTING=ON, ordinary root configuration with bundled submodules. Windows CMake 3.28 validation used CMAKE_CXX_SCAN_FOR_MODULES=OFF to avoid its existing MinGW module-mapper probe failure; this PR adds no build flag or dependency.

Built guest_suppressed_scanning_tests, guest_formatting_tests and guest_scan_count_tests, then ran:

ctest --test-dir build-validate --output-on-failure --no-tests=error -R '^guest_(suppressed_scanning|formatting|scan_count)$'

3/3 passed on both OSes after rebasing onto main ea2bbefb2: Windows 0.49 s total; Linux 0.86 s total. New coverage includes sscanf/vsscanf and secure scans, %*d/%*s/%c/%[...]/%*f, %n, real EOF, matching failure, multiple suppressions, earlier assignments, more destinations than fit in argument registers, positional destinations, scanset literals, a regular FILE and a pipe.

Negative control on the unchanged Linux implementation: guest_suppressed_scanning failed while the two existing control tests passed. The corrected implementation passed all three. git diff --check and the repository conventions checker passed.

No title, console, macOS or performance claim. The full test suite was not run for this PR. Full upstream PR builds require a collaborator's manual Build workflow.

  • Title evidence (static, no title run): 21 of the 63 catalog executables call sscanf with a format that has an assignment-suppressed conversion, FFmpeg's subtitle and HTTP parsers among them; the list and the method are in this comment.

Checklist

  • Based on current main; no open PR implements this Linux suppression fix
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stub added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source; none added here
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839428808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966). Originally posted by [Dripl1x](https://github.com/Dripl1x) on 2026-10-13T06:42:16Z. --- ### What Linux host scanf can return EOF after a successful assignment-suppressed conversion: `sscanf("12", "%*d%d", &value)` returns EOF although input was already converted. Return 0 in that case, matching the existing Windows path and [FreeBSD's conversion-count handling](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libc/stdio/vfscanf.c#L757-L763). Instrument suppressed input conversions with internal count destinations and forward all destinations through the existing SysV argument representation. The host scanner still reads the input once, including non-seekable streams. Keep true EOF before an input conversion, assignment counts, caller `va_list`, positional destinations, scansets and the existing pre-C23 `%i` behavior. Formats without suppression retain the direct host path. Existing unsupported guest-wide conversions remain rejected. Related: #4815 changes Windows integer widths in WindowsScanning.hpp and its formatting test. This PR changes the Linux path and adds a separate suppression test; it does not depend on that PR and does not modify its files. Related: #5285 and #5291 replace the same Linux call sites in Formatting.cpp to scan 16-bit wide conversions. The changes are independent and neither builds on the other; a trial merge conflicts only on those lines and keeping both sides resolves it. Order agreed with their author: this PR goes first, and #5285 and #5291 rebase onto it and list it as their dependency ([proposal and resolution](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6151268956), [agreement](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6152056305)). ### Tested Windows, supported WinLibs MinGW-w64 GCC 15.2.0; Linux, Ubuntu 26.04 under WSL, GCC 15.2.0. Release, BUILD_TESTING=ON, ordinary root configuration with bundled submodules. Windows CMake 3.28 validation used CMAKE_CXX_SCAN_FOR_MODULES=OFF to avoid its existing MinGW module-mapper probe failure; this PR adds no build flag or dependency. Built guest_suppressed_scanning_tests, guest_formatting_tests and guest_scan_count_tests, then ran: ```sh ctest --test-dir build-validate --output-on-failure --no-tests=error -R '^guest_(suppressed_scanning|formatting|scan_count)$' ``` 3/3 passed on both OSes after rebasing onto main ea2bbefb2: Windows 0.49 s total; Linux 0.86 s total. New coverage includes sscanf/vsscanf and secure scans, %*d/%*s/%*c/%*[...]/%*f, %n, real EOF, matching failure, multiple suppressions, earlier assignments, more destinations than fit in argument registers, positional destinations, scanset literals, a regular FILE and a pipe. Negative control on the unchanged Linux implementation: guest_suppressed_scanning failed while the two existing control tests passed. The corrected implementation passed all three. git diff --check and the repository conventions checker passed. No title, console, macOS or performance claim. The full test suite was not run for this PR. Full upstream PR builds require a collaborator's manual Build workflow. - Title evidence (static, no title run): 21 of the 63 catalog executables call `sscanf` with a format that has an assignment-suppressed conversion, FFmpeg's subtitle and HTTP parsers among them; the list and the method are in [this comment](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6157622819). ### Checklist - [x] Based on current main; no open PR implements this Linux suppression fix - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stub added - [x] No notes, investigation .md files or images added to the repository - [x] New third-party code is a submodule built from source; none added here - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (OpenAI Codex)
xXPBSXx commented 2026-10-13 08:21:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:21:02Z.


Windows test of this PR.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2, libusb-cmake from a local checkout. Built from main c2565f014 with this PR and ten other open PRs (#4972, #4967, #4966, #4945, #4938, #4936, #4933, #4898, #4896, #4888) merged together; the merges had no conflict.

Result: guest_suppressed_scanning (1 of 1) pass.

Not checked: whether the test fails without the change in the library code; the PR was not tested alone, only in the combined merge; no title run; Linux not tested.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141391808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6141391808). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:21:02Z. --- Windows test of this PR. Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `BUILD_TESTING=ON`, `-j2`, `libusb-cmake` from a local checkout. Built from `main` `c2565f014` with this PR and ten other open PRs (#4972, #4967, #4966, #4945, #4938, #4936, #4933, #4898, #4896, #4888) merged together; the merges had no conflict. Result: guest_suppressed_scanning (1 of 1) pass. Not checked: whether the test fails without the change in the library code; the PR was not tested alone, only in the combined merge; no title run; Linux not tested. AI-assisted (Claude Code).
Dripl1x commented 2026-10-13 17:25:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T17:25:54Z.


@Nixitov the PR overlap report lists #5285 and #5291 against this PR: all three replace the same Linux call sites in core/libs/prx/libc/src/Formatting.cpp.

The changes are independent. This PR routes the narrow host path through ScanHostString_nid_no_patch / ScanHostFile_nid_no_patch, so a suppressed conversion before EOF returns 0. Yours select ScanWideGuest / ScanWideFile for formats with 16-bit wide conversions.

A trial git merge-tree of 32d402845 with c8362661d and with cf96193cf conflicts only in that file, and keeping both sides resolves it:

const int result = HasGuestWideScan(format) ? ScanWideGuest(input, format, args) : ScanHostString_nid_no_patch(input, format, args);

in vsscanf_nid_postfix and sscanf_nid_postfix, the same with ScanWideFile / ScanHostFile_nid_no_patch in fscanf_nid_postfix, and both helper blocks kept after HostVfscanf for #5291. I have not built the merged result.

Proposed order: this PR first (opened earlier, with an independent Windows run above), then #5285 and #5291 rebase with that resolution. If you prefer the opposite order, say so and I will rebase onto yours and declare it in Depends on here.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151268956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6151268956). Originally posted by [Dripl1x](https://github.com/Dripl1x) on 2026-10-13T17:25:54Z. --- @Nixitov the PR overlap report lists #5285 and #5291 against this PR: all three replace the same Linux call sites in `core/libs/prx/libc/src/Formatting.cpp`. The changes are independent. This PR routes the narrow host path through `ScanHostString_nid_no_patch` / `ScanHostFile_nid_no_patch`, so a suppressed conversion before EOF returns 0. Yours select `ScanWideGuest` / `ScanWideFile` for formats with 16-bit wide conversions. A trial `git merge-tree` of `32d402845` with `c8362661d` and with `cf96193cf` conflicts only in that file, and keeping both sides resolves it: ```cpp const int result = HasGuestWideScan(format) ? ScanWideGuest(input, format, args) : ScanHostString_nid_no_patch(input, format, args); ``` in `vsscanf_nid_postfix` and `sscanf_nid_postfix`, the same with `ScanWideFile` / `ScanHostFile_nid_no_patch` in `fscanf_nid_postfix`, and both helper blocks kept after `HostVfscanf` for #5291. I have not built the merged result. Proposed order: this PR first (opened earlier, with an independent Windows run above), then #5285 and #5291 rebase with that resolution. If you prefer the opposite order, say so and I will rebase onto yours and declare it in `Depends on` here. AI-assisted (Claude Code).
Nixitov commented 2026-10-13 18:10:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T18:10:09Z.


Thanks @Dripl1x — your order works for us: land #4966 first, and we'll rebase #5285 and #5291 onto it (and list Depends on: #4966).

The resolution you wrote is exactly right: keep your ScanHostString_nid_no_patch / ScanHostFile_nid_no_patch on the narrow path and select our scanner only when the format has a 16-bit wide conversion, e.g.

const int result = HasGuestWideScan(format) ? ScanWideGuest(input, format, args) : ScanHostString_nid_no_patch(input, format, args);

in vsscanf_nid_postfix and sscanf_nid_postfix, and the same with ScanWideFile / ScanHostFile_nid_no_patch in fscanf_nid_postfix, keeping both helper blocks after HostVfscanf. Both sides only replace the call site, so nothing else moves.

Thanks for the merge-tree check on c8362661d and cf96193cf — we'll fold that in when we rebase and re-run the tests.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152056305 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6152056305). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T18:10:09Z. --- Thanks @Dripl1x — your order works for us: land **#4966 first**, and we'll rebase **#5285** and **#5291** onto it (and list `Depends on: #4966`). The resolution you wrote is exactly right: keep your `ScanHostString_nid_no_patch` / `ScanHostFile_nid_no_patch` on the narrow path and select our scanner only when the format has a 16-bit wide conversion, e.g. ```cpp const int result = HasGuestWideScan(format) ? ScanWideGuest(input, format, args) : ScanHostString_nid_no_patch(input, format, args); ``` in `vsscanf_nid_postfix` and `sscanf_nid_postfix`, and the same with `ScanWideFile` / `ScanHostFile_nid_no_patch` in `fscanf_nid_postfix`, keeping both helper blocks after `HostVfscanf`. Both sides only replace the call site, so nothing else moves. Thanks for the `merge-tree` check on `c8362661d` and `cf96193cf` — we'll fold that in when we rebase and re-run the tests. AI-assisted: yes
Dripl1x commented 2026-10-13 23:48:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T23:48:44Z.


Which titles reach this path, from a static survey of the homebrew catalog (no title was run):

  • 58 of the 63 executables call sscanf, 39 vsscanf and 19 fscanf.
  • In 21 of them at least one recovered sscanf format has an assignment-suppressed conversion, so on Linux those calls take the instrumented path this PR adds. The most common ones are FFmpeg's subtitle and HTTP parsers: %d%*1[:/]%d%c (15 titles), %*X %X %X %X (12), %*3d:%*2d:%*2d%c, {%*d}{%*d}%c, %*s %*s %u and Dialogue: %*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d,%n (11 each), HTTP/%*s %d (5).
  • The 21 titles: PPSA19111, PPSA74126, PPSA76677, PPSA85300, PPSA97358, PPSA99003, PPSA99008, PPSA99039, PPSA99082, PPSA99109, PPSA99110, PPSA99141, PPSA99177, PPSA99288, PPSA99420, PPSA99505, PPSA99515, PPSA99773, PPSA99810, PPSA99920, PPSA99997.

Several of these formats end in %c after suppressed conversions, the shape of the case in the description (%*d%d on input that ends): the host returns EOF where FreeBSD returns 0.

Method: the 65 release archives listed in ps5-homebrew-catalog were downloaded (SHA-256 equal to the catalog records), 63 of them hold an eboot.bin, which was unwrapped from its fake-signed container. Nothing was run. Imports come from relinker --registry and tools/import_audit.py on main bfc10637d. Call arguments are read from the instructions before each call site (objdump), which recovers a value only where the compiler loads a constant right before the call, so every count below is a lower bound.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157622819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6157622819). Originally posted by [Dripl1x](https://github.com/Dripl1x) on 2026-10-13T23:48:44Z. --- Which titles reach this path, from a static survey of the homebrew catalog (no title was run): - 58 of the 63 executables call `sscanf`, 39 `vsscanf` and 19 `fscanf`. - In 21 of them at least one recovered `sscanf` format has an assignment-suppressed conversion, so on Linux those calls take the instrumented path this PR adds. The most common ones are FFmpeg's subtitle and HTTP parsers: `%d%*1[:/]%d%c` (15 titles), `%*X %X %X %X` (12), `%*3d:%*2d:%*2d%c`, `{%*d}{%*d}%c`, `%*s %*s %u` and `Dialogue: %*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d,%n` (11 each), `HTTP/%*s %d` (5). - The 21 titles: PPSA19111, PPSA74126, PPSA76677, PPSA85300, PPSA97358, PPSA99003, PPSA99008, PPSA99039, PPSA99082, PPSA99109, PPSA99110, PPSA99141, PPSA99177, PPSA99288, PPSA99420, PPSA99505, PPSA99515, PPSA99773, PPSA99810, PPSA99920, PPSA99997. Several of these formats end in `%c` after suppressed conversions, the shape of the case in the description (`%*d%d` on input that ends): the host returns `EOF` where FreeBSD returns 0. Method: the 65 release archives listed in [ps5-homebrew-catalog](https://github.com/blackbearreloaded/ps5-homebrew-catalog) were downloaded (SHA-256 equal to the catalog records), 63 of them hold an `eboot.bin`, which was unwrapped from its fake-signed container. Nothing was run. Imports come from `relinker --registry` and `tools/import_audit.py` on `main` `bfc10637d`. Call arguments are read from the instructions before each call site (`objdump`), which recovers a value only where the compiler loads a constant right before the call, so every count below is a lower bound. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-14 02:33:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:16Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159591520 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4966#issuecomment-6159591520). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:16Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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