fix(libc): decode a wide printf %s as titles' libc.prx does, failing on invalid UTF-8 #9953
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9953"
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-22T23:43:16Z.
What
The wide printf family (
swprintf,vswprintf,wprintf,fwprintf, …) decodes a narrow%sargument into UTF-16. Up to now it accepted UTF-8 of up to 4 bytes and turned any byte that didn't form a character into U+0000–U+00FF. Thelibc.prxthat titles ship decodes differently. It accepts at most 3 bytes per character, the same limit #8855 measures in the firmware's multibyte functions. On anything else it fails the whole call. Console vsmain:main[%s]ofF0 9F 98 80errno86 (EILSEQ), buffer[[, U+D83D U+DE00,]x%syof80,C3,E2 82,FForC3 A9 C3EILSEQ, bufferx[%s]ofC0 80thenA[][, U+0000,][%s]ofC1 81orE0 81 81[A][, U+00C1, U+0081,][%3s]of"", or[%3.0s]ofAB[][ ][%.0s]of80EILSEQ[]Rules followed, all read from that
libc.prx:ED A0 BD ED B8 80is U+D83D U+DE00, the form #9939 writes for%ls.swprintfandvswprintfthen return -1 witherrnoEILSEQ. The buffer keeps the text produced before that conversion.C0 80, ends the string.%.1sofA\x80isA, while%.2sof it fails and so does%.0sof\x80.%ls/%Sof the wide family still pads an empty string, as the console does.Implementation.
AppendUtf16applies these rules and reports a failure.FormatWidethen throwsWideEncodingErrorwith the text so far.vswprintfwrites that text and setsEILSEQ.wprintfandvfwprintfsetEILSEQinstead ofEINVAL. The secure forms fail as before. The debt file records the stream and secure behaviour as unverified.Tested
Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head
d777f1973b80b3056827557c713bef216d675227on tested main3fea2a937ba9fbab2f06c51691fe0c5763659aa3. The topic production/test edits and current main's includes and checked-pointer behavior are preserved.Linux Release focused rebuild: Narrow/wide formatting, stdio variadic and public headers each pass three times: 12 passes, zero skips. Conventions, whitespace and merge checks pass. Every refreshed head's submodule pointers match the pinned main; the private dependency checkouts used for the gates are aligned. No new negative-control, Windows, console, title, GPU, full-suite or performance run is claimed. Earlier measurements below retain their original exact pins. Fulfilled merge-order dependencies have been cleared from the checklist; open prerequisites remain.
Exact source/dependency pins, patch-preservation and gitlink proofs, builds, verbose tests, JUnit and lease-push receipts. SHA-256:
702c4110ee9dde421c2dd5e057ed53a2df05e0cf7b01f67e8fb9cb779e332f7c; downloaded copy verified.Linux follow-up (2026-10-23 UTC): Fresh Release configuration of exact head
8bffaa164af60bb9be39d93b58b5c821bd4e1a01on Arch Linux 7.2.9 / glibc 2.44 / GCC 16.2.1.guest_wide_formattingpasses 1/1 in three runs, with no skips, exercising the new decoder, guesterrno == 86, partial-buffer handling and width/precision cases. Negative control: retain the PR tests but substitute parent24c6cc33f090296ab90dc154abdfb9ef548fc923'sFormattingWide.cpp; it builds and the same test aborts atswprintf rejects a 4-byte sequence and keeps the output before it. Source restored clean afterward; the private build's last executable is the negative control. Full build/test logs, source pins, validator and review (SHA-256b5a63de38830d7486e72610e0b0843eaa194d24f42e678fd0405e37984bfb751). Exact-head focused Linux evidence; no latest-main, full-product, native-console or title claim.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main24c6cc33f0, head 8bffaa164a.Differential run. A scratch loader runs PPSA07923's decrypted
libc.prxnatively. It compares itsswprintf(nJz16JE1txM) with this build'sswprintf_nid_postfix, checking the result, the units written anderrno.[%s],[%.1s],[%3s]and[%hs]on 13 strings:A é,€, a 4-byte U+1F600, its 3-byte surrogate form,80,C3,C3 x,E2 82,FF,C0 80,E0 80 80,EF BF BFandF4 8F BF BF.maindiffers in 36 of the 52 cases; this build in none.guest_wide_formatting. Updated tests:Checkrows and theswprintfsurrogate test used a 4-byte U+1F600, which the console rejects. They now use its 3-byte surrogate form, with the console's results.%ntest now counts that form's two units.EILSEQand the partial buffer, overlong NUL andA, precision before and at an invalid byte, precision zero, and empty and non-empty fields with a width.The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. With
main'sFormattingWide.cppand these tests,guest_wide_formattingaborts.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Overlap. Merges cleanly with #9927 and #9596, which also edit
FormattingWide.cpp. #9527 and #5303 have a neighbouring-line conflict indocs/dev/debt/libc.md.Not tested. A native console; the output of
wprintf/fwprintfon such a string.Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12:
guest_wide_formattingpassed 1/1 with this PR'sFormattingWide.cppandGuestWideFormatting.cpp. That reused an older configured tree with the PR's sources overlaid, so it is a focused Linux run, not a clean CI build.Linux (reviewer run, exact head): Dom3005 ran head 8bffaa164a merged onto
main83462cc57 in an Ubuntu 26.04 container (GCC 15.2.0, glibc 2.43, Release,BUILD_TESTING=ON):guest_wide_formattingpassed 3/3, including theEILSEQassertions. The negative control was not run there.Checklist
main; no other open PR changes how the wide family decodes%sNotImplemented_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)AI-assisted (Claude Code).
Conflict refresh, 2026-10-27 UTC: exact head
f40626ee7bb854b9b3ced6a9eec54d4ea667dc02on tested main74acfad65b3f0fd4eab653f3a3989d298fba1157. Preserved the wide UTF-8 conversion topic and current main's added test includes and debt.Linux Release focused libraries/executables rebuilt. Three groups (wide formatting, narrow formatting, public headers) each pass three times: 9 initial and 9 restored passes. Main-production-only FormattingWide control fails the intended wide-formatting group; restored libc is byte-identical. Zero skips; conventions and whitespace pass. This is focused Linux evidence, without new Windows, console, title, GPU or full-suite validation. Earlier measurements retain their original exact pins.
Source/dependency pins, production preservation, verbose build/test/control/restoration logs, JUnit, hashes and lease-push receipts. SHA-256:
594bf1dd3a57728c23dd0752926f501f34a8be8e31c8d924e6bec3723d029a82; downloaded copy verified.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T00:30:14Z.
Review: APPROVED
Reviewed the decoder, failure path, width/precision behavior, partial-buffer handling, and regression cases. The test includes a valid prefix followed by invalid input and asserts that output from the current conversion is not committed, matching the reported console behavior. I ran the focused Linux
guest_wide_formattingtest; it passed 1/1 using the PR head’s changed implementation and test sources in the existing configured build. The author’s Windows differential evidence is extensive, and required hosted checks pass; full Linux/Windows product CI remains skipped by policy. Approved at head 8bffaa164af60bb9be39d93b58b5c821bd4e1a01.