fix(libc): read swscanf scanset ranges and string lengths as titles do #12420
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12420"
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 JJenkx on 2026-10-28T13:01:57Z.
What
swscanfandswscanf_sthrew for three things that titles' ownlibc.prx(PPSA07923 and PPSA05916 agree on every row) reads without trouble. A title that hit any of them stopped.Scanset ranges. Members are read left to right.
X-Yis a range when a-follows a member and isn't the last character before]:bca-%[a-c]bcaza%[z-a]-ab/a-b%[-a]/%[a-]-a/a-: a first or last-is a memberb/a-c%[a-a-c]a-c: after a range,-is a member again+%[*--]*to-b]%[]-c]]that opens the set can start a rangeéa%[a-é]dcb/-]a%[^a-c]/%[^]-]d/ 0Lengths on
%s,%cand%[.h,hh,ll,j,zandLread narrow, like no length. Onlylreads wide. Here every length butlthrew.Unknown conversions.
%y,%5yand%hls(hfollowed by the conversionl) are matching failures. Here they threw.Unknown integer and floating lengths,
%nwith suppression or width, and narrow input thatwcrtombcan't convert still throw; those weren't measured.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmain750cf6cf48.libc.prx: I loaded PPSA07923's and PPSA05916'slibc.prxnatively and called theirswscanfby NID (HNnWdT43ues) side by side with this build. Over 66 input/format pairs, comparing the return value,errno, the bytes or units stored and%n:mainthrows on the first range,%hsor unknown conversion; the other rows already matched;guest_wide_conversion(21 new rows; the two "scanset range throws" checks now expect the measured result),guest_wide_stream_scanandguest_stdio_variadicpass in each of 3 runs.main'sScanningWide.cpp,guest_wide_conversionfails.Not tested on Linux or macOS. The scanner is the same code on every platform.
Overlap:
tools/pr_overlap.pyreports #9087, #9863 and #10729, all editing the same longswscanfdebt entry (libc.mdline 201). This PR changes only its "It throws for ..." sentence. #10324 touchesScanningWide.cppin unrelated stream-orientation lines. I've asked on #9087, #9863 and #10729 to let theirs land first; I'll rebase after each.Empty-input provenance clarification — 2026-10-29
Added the requested provenance caveat in
3961a1f069963e5cf67d70124ae8c9c0576b51d1: unknown conversions at end of input (for example%yon empty input) were not established by the published measurements, and their matching-failure result is explicitly unverified. This does not treat the separately measured empty unterminated-scanset rows as evidence for%y.Only one debt sentence changes. Production, tests, public headers and submodule pointers are unchanged. Conventions against current main and whitespace pass (the existing long-entry warning remains), and the current-main merge preview is clean; no new runtime, Windows or SDK measurement is claimed. The range-rule change in the narrow scanner’s
InWideScansetis separately implemented by #12468, rather than claimed as part of this PR. Pending external merge-order confirmations remain pending.Patch and source-preservation receipt, SHA-256
c08b29d044ad929bf7d681059a6a330959ab81edf8784502dcc369f3148b49f9.AI-assisted: yes (Codex).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T13:08:47Z.
Review: COMMENTED
Reviewed head
96363b0687on macOS, since the description says Linux and macOS weren't tested. Setup: macOS 26 (Apple silicon), Apple clang 21.0.0, libc++, C++20, built for x86_64 and run under Rosetta. arm64 can't buildScanningWide.cppat all because of thesizeof(long double) == 16static asserts.Setup.
guest_wide_conversionisn't in the relinker-only lane and the full libc target needs submodules, so I compiledScanningWide.cppalone (head, thenmain750cf6cf48's copy) against a small harness. The harness stubs only the 7 imports the object needs: UTF-8wcrtomb, ASCIIiswspace, and stream functions that abort if called. It runs the 21 rows from the new test table plus 7 more:%js,%zs,%Ls,%ts,%[]]onab,%[]-]on]-a, and%yon empty input. Each row checks the return value and the stored bytes against an untouched!buffer.Head, ASan+UBSan: all 21 PR rows and the 6 extra length/scanset rows pass. No sanitizer reports.
main'sScanningWide.cpp: 23 of the 28 rows fail. 12 throwscanset range is implementation-defined, 7 throwinvalid string length modifier(h,hh,ll,j,z,L,t) and 4 throwunsupported conversion(%y×3 and%hls, reported as conversion 108 =l). The 5 rows with no range (%[-a],%[a-],%[^]-],%[]],%[]-]) already pass. So the change is exactly the three throws the description lists.Mutants on
InSet/Conversion, all killed by the PR's own 21 rows:member + 2 <→member + 1 <, so a trailing-starts a range: only the%[a-]row fails (my extra%[]-]row fails too).member += 3→member += 1, so ends are re-read and-stops being a member again after a range: 5 rows fail.&&→||: 7 rows fail.[min, max]:%[z-a]and%[a--]fail.Matching→Input: the 3 unknown-conversion rows fail.So the table pins the range parsing tightly.
git merge-treeagainstupstream/main750cf6cf48is clean.check_conventions --base upstream/mainwith this title and body reports 0 errors. Its one warning,debt-lengthonlibc.md:201at 3265 characters, was already over the limit onmain(3083).One non-blocking question. With no input left, an unknown conversion returns 0 on this branch:
swscanf(u"", u"%y", …)gives 0, and so doesu" "withu" %y".%dand%son the same empty input returnEOF(-1). That matches what%S/%Calready do onmain, and the debt entry says for those that "whether input ending before them is an input failure instead is unverified". If your 66 pairs didn't include an empty-input unknown conversion, it may be worth adding "unknown conversions" to that unverified clause, since the new sentence says they "follow thelibc.prxof PPSA07923 and PPSA05916" without that caveat. If they did include it, a row for it in the table would lock it in.AI-assisted: yes (Claude Code); everything above was run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:26:57Z.
Review: CHANGES_REQUESTED
Review — changes requested for overlap coordination
I reviewed the scanner changes on head
a51d64dbb74f749fcd422aedbc73800c4f84c644. The scanset walker handles the reported left-to-right range/member cases, and the text/unknown-conversion paths match the Windows title-library measurements described in the PR. I found no new code defect in the changed logic. The author reports 66 differential cases with zero mismatches, three passing runs of the focused Windows suites, and a negative control. I did not run the harness locally.I cannot clear the overlap/readiness blocker yet. The proposed order (#9087, #9863 and #10729 first, then this PR) is recorded as pending, and the #9863 author has not confirmed the #9863-first sequence. Please obtain confirmation from the overlapping authors and keep the Depends on list aligned with those agreements. Current main also changed the shared
docs/dev/debt/libc.mdafter this branch’s base; the merge preview is clean, but the debt hunk needs reconciliation against that current version.After the order and debt entry are settled, the existing scanner test results remain relevant if production/test files are unchanged; rerun conventions/overlap checks on the integrated head. Hosted policy and build checks currently pass, with Linux product CI skipped.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T20:19:10Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The exact-head Linux test report is useful, but the PR still records the overlapping authors’ landing-order agreement as pending.
What I ran
3961a1f069963e5cf67d70124ae8c9c0576b51d1; PR base recorded ase4da19aff06e25ae16b90f460dff22e8ac1eb786; currentmain:fd9b3f62d43d6753d28a31a7c285e1f51e9c1b42.Results
main; GitHub reports the PR mergeable.guest_wide_conversionpassed 3/3. I did not run it.Negative control
Findings
Blocking
The checklist says
Depends on: #9087, #9863, #10729but also says the authors’ agreement is pending. The current contribution rule says to agree with authors of overlapping PRs which lands first and declare that order withDepends on. Please obtain the confirmations and update the checklist to the agreed order before requesting approval.Non-blocking
The author’s exact-head Linux test report is useful, and the latest change is documentation-only. I found no new scanner-code issue in this head. I did not independently run the test or the convention checks.
Sources
mainfd9b3f62d43d6753d28a31a7c285e1f51e9c1b423961a1f069963e5cf67d70124ae8c9c0576b51d1Not verified
No local build, focused test, convention check, or negative-control mutation. Linux product CI is skipped by the workflow.
To get this to a good state
Obtain explicit author agreement on the order for the overlapping PRs and update the checklist accordingly. I will recheck the same merge, overlap, convention, and focused-test state on the updated head.