feat(libc): scan 16-bit wide conversions in the sscanf family on Linux #7525
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7525"
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 AlexOfTheForest on 2026-10-18T12:06:17Z.
What
On Linux,
sscanf,vsscanf,sscanf_sandvsscanf_sthrew for the 16-bit wide conversions (%ls,%lc,%l[,%S,%C), because glibc would store a 32-bitwchar_tper character into the guest's 16-bit buffer.ScanGuest, the per-directive scanner the_sforms already use, now scans those fields itself:_ssize count characters.%lsskips leading white space and stops at the next.%l[matches an ASCII scanset with ranges, negation and a leading].%lcreads the field width (default 1) without a terminator; a field that meets the end of the input early keeps what it read and counts as converted, as FreeBSD'sconvert_wchardoes._ssizing mirrors the narrow path: a too-small array gets a null first element and the conversion fails.sscanfandvsscanfsend a format with a wide conversion throughScanGuest; any other format keeps the host path.UTF-8 decoding and scanset matching live in the new
ScanWideField.cpp. It throws for input that is not UTF-8, a character outside the BMP, a scanset member outside ASCII, and positional arguments next to a wide conversion. Wide conversions infscanfstill throw, since it reads a stream, not a string. The libc debt entry records all of this, plus the fact that FreeBSD decodes with the locale'smbrtowcand that the console's locale encoding is unverified.Progress report:
vsscanf_nid_postfixmoves from stub to implemented (+1). Its Linux path now handles these formats instead of throwing; the remaining unsupported cases throw fromScanWideField.cpp.Tested
Linux x86_64:
guest_formattingcases replacing the old "rejects" checks cover:%ls/%lc/%S/%C,%3lcwithout a terminator, scansets (range, negation, leading]), Czech UTF-8 text with widths, suppression, mixing with narrow and%d/%n,EOFand matching failures,vsscanfthrough ava_list, the_ssizing cases, and each remaining throw.guest_formattingfails.tools/check_conventions.py --base upstream/mainpasses.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 github-actions[bot] on 2026-10-18T12:07:01Z.
Progress report (
9127ea3→675ff30)📈 System libraries: 79.85% (+0.02%, +1 implemented functions)
✅ 1 implemented
vsscanf_nid_postfixImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:09:20Z.
Code review location:
core/libs/prx/libc/src/ScanWideField.cpp; line 65This rejects any
$anywhere in the format, including a literal dollar sign. For example, scanning input"$word"with format"$%ls"reaches this guard and throws, even though the$is not part of a positional conversion. Could this detect$only inside conversion directives (or otherwise distinguish literal text) before rejecting positional wide scans?Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T12:36:35Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL114-115core/libs/prx/libc/src/Formatting.cppL11, L47-48, L54, L62-63, L157-161, L390, L409, L412, L431, L524core/libs/tests/Formatting.cppL284-294docs/dev/debt/libc.mdL115Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/Formatting.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/Formatting.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/Formatting.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/Formatting.cppcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Formatting.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/Formatting.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:10:03Z.
Re-checked against current main: the new stream-scanf and
vfprintfchanges don't touch thesscanf/vsscanf/sscanf_spaths here, the merge is clean, andfscanf/vfscanfstill throw for wide conversions throughRejectGuestWideScan; merged.