fix(libc): retain suppressed scanf conversions before EOF #4966
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4966"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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%ibehavior. 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:
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.
sscanfwith 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
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-cmakefrom a local checkout. Built frommainc2565f014with 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).
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 selectScanWideGuest/ScanWideFilefor formats with 16-bit wide conversions.A trial
git merge-treeof32d402845withc8362661dand withcf96193cfconflicts only in that file, and keeping both sides resolves it:in
vsscanf_nid_postfixandsscanf_nid_postfix, the same withScanWideFile/ScanHostFile_nid_no_patchinfscanf_nid_postfix, and both helper blocks kept afterHostVfscanffor #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 onhere.AI-assisted (Claude Code).
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_patchon the narrow path and select our scanner only when the format has a 16-bit wide conversion, e.g.in
vsscanf_nid_postfixandsscanf_nid_postfix, and the same withScanWideFile/ScanHostFile_nid_no_patchinfscanf_nid_postfix, keeping both helper blocks afterHostVfscanf. Both sides only replace the call site, so nothing else moves.Thanks for the
merge-treecheck onc8362661dandcf96193cf— we'll fold that in when we rebase and re-run the tests.AI-assisted: yes
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):
sscanf, 39vsscanfand 19fscanf.sscanfformat 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 %uandDialogue: %*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d,%n(11 each),HTTP/%*s %d(5).Several of these formats end in
%cafter suppressed conversions, the shape of the case in the description (%*d%don input that ends): the host returnsEOFwhere 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 fromrelinker --registryandtools/import_audit.pyonmainbfc10637d. 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).
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.
Pull request closed