fix(libc): follow measured wide printf behavior #5303
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5303"
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 MarcZX10 on 2026-10-13T16:46:28Z.
What
Updates non-secure guest wide
printfformatting to match the measured literal-text behavior for%q,%D/%O/%U, unknown conversions, and width handling observed fromlibSceLibcInternal.sprxon firmware 12.70. The probe calledswprintffrom a payload process; it did not exercise a title or its bundledlibc.prx, whose Dinkumware_Printfbehavior remains unverified. The probe also showed that a trailing%read past the format terminator, so incomplete conversions continue to fail safely. The securesnwprintf_spath continues to reject these forms because its console behavior was not measured.The original implementation commits retain Hussein Kadhim as author, and the original test commits retain MarcZX100. The review follow-up is authored by MarcZX10.
Tested
6de675ebf48b46bb5546a4c8a606e54ce480d08dis based onmain0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb; the existing authored commits were preserved.git diff --check, the conventions/template check, and the merge preview passed.pr_test_quality.pyemitted a possible-unregistered C++ test warning. Inspection ofcore/libs/prx/libc/CMakeLists.txtconfirms thatguest_wide_formatting_testsis registered with CTest asguest_wide_formatting.06bd24679818bec01461f191fec3e6d745ca88b6builtguest_wide_formatting_testsand passedctest -R guest_wide_formatting --output-on-failure(1/1). Build and CTest were not rerun after rebasing.libc.prxruntime test, Windows build or full test suite was run.Checklist
main; no other open PR implements the same wide-format functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:30:50Z.
Which title prints
%q,%D/%O/%U, an unknown conversion or a trailing%through the wideprintffamily? The source here is FreeBSD 11.4, but the console'slibc.prxformats through Dinkumware's_Printf, which can handle unknown conversions andqdifferently (same question as the review on #3987). Until a title reaches it, or_Printfin a title'slibc.prxconfirms these cases, main's throw is the safer behaviour.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T05:03:51Z.
I do not have title traces or Dinkumware _Printf evidence for these wide-format cases. The current evidence is FreeBSD 11.4 behavior and Linux-side tests, so I cannot claim console compatibility for %q, %D/%O/%U, unknown conversions, or a trailing %. I agree this leaves the added behavior unverified against the console; absent title or _Printf evidence, main’s throw is safer. I will avoid presenting these cases as title-required until we have that evidence.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:34:18Z.
Review: CHANGES_REQUESTED
Thanks for the fix. Blocking points:
libc.prxformats through Dinkumware's_Printf, not FreeBSD'svfwprintf. As discussed above, neither a title nor_Printfevidence shows that%q,%D/%O/%U, unknown conversions (with width) or a trailing%behave as FreeBSD 11.4 does there; main's throw is the safe behaviour until then. Evidence that would unblock it: the relevant branches of_Printfdisassembled from a title'slibc.prx(same approach as in #3987), or a title that reaches these cases.core/libs/tests/GuestWideFormatting.cpp; it needs a rebase.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:35:52Z.
Thanks for the detailed blocking review. I have no new title trace or Dinkumware
_Printfevidence, so the current FreeBSD/Linux results still do not justify claiming console behavior. I’ll leave the PR unrebased until that evidence exists; the relevant_Printfbranches or a title reaching these conversions remain the needed next step.Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T10:34:28Z.
I have some hardware data for these cases, though not the kind the review asks for. @adriadam10: this is libSceLibcInternal.sprx's
swprintfin a payload process on a PS5 (firmware 12.70), not_Printfin a title'slibc.prx. I have no title trace and did not disassemblelibc.prx, so this does not settle the blocking point.Setup: an ELF payload (ps5-payload-dev/sdk v0.44, clang 18.1.8), started from a payload manager, resolves
swprintffrom libSceLibcInternal.sprx and callsswprintf(buf, 40, fmt, a1, a2, a3, 0, 0)with a 16-bitwchar_t. Each ASCII format is copied unit by unit, NUL included, into the samewchar_t fmt[48], which is never cleared.textis the output up to its first NUL (nul_at), logged as ASCII (?for any other unit; none appeared).Compared with
CheckFreebsdConversionsincore/libs/tests/GuestWideFormatting.cppand the new line indocs/dev/debt/libc.mdat 178de73:q,%D,%O,%Uprint as written.h/hhare dropped, and the width pads the printed text:%5qdgives%qd,%5Dgives%Dand%-4Ogives%O. The test expects-5|7|ff| 9(13),5000000000|10|18446744073709551615(34) and70000|70000| -3|10 |(23). My arguments differ from the test's (5, 300, 7for the third format), but no argument appears in these three outputs.%ykeeps its%, and the width counts both characters:[%-5y]gives[%y ]. The test expectsy|[ %]|[y ]|€(19); I ran the format without|%€.[%5%]matches.%05yis blank-padded, as the debt line says, but it prints%y, noty.%: the test expects100(3) for"100%"and7(1) forFormat(buffer, 48, u"%d%", 7). Hereswprintfprinted the%and kept reading past the terminator. After100%,fmtstill held5%]|[%-5y]from the earlier%y|[%5%]|[%-5y], and that tail appears formatted in the output. The same tail follows3%in the%d%case, which also passed the terminator100%had left. I ran this throughswprintf, notvswprintf. What gets printed depends on the memory after the format, but it did not stop at the%.%mand%lqd: the debt line says these "still fail", and the test expects a negative return (and an empty buffer for%m). Here they print as text:%m(2) and%qd(3).Main does not match this output either:
vswprintf_nid_postfixreturns -1 with an empty buffer whenFormatWidethrows (FormattingWide.cppon main), and every case above throws there. In this process, all of them came back as text.Not measured: a title or its
libc.prx;vswprintfandwprintf; all thesnwprintf_scases; the surrogate-pair cases;|%€,ab%5,%d%l, a lone%and%lp. Each case ran once.I can attach the probe source and the full log if that helps.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:01:07Z.
Rebased onto current main (
00d7e611ef). Preserved all three commits and original authorship.git diff --checkpasses. I attempted a Linux CMake configure for focused validation, but configuration is blocked because the checked-out SDL2 source lacksCMakeLists.txtand XRandR development support is unavailable; no local test executable was built. The PR checks are running on the updated head.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T15:03:16Z.
Review: CHANGES_REQUESTED
Thanks for the rebase. Blocking points:
swprintffromlibSceLibcInternal.sprxon firmware 12.70) contradicts the behaviour this PR implements:%qd,%D,%O,%Uand unknown conversions such as%yare printed as literal text (width pads the whole%y/%qd;h/hhare dropped), and%mand%lqdprint as text too. The PR formats them the FreeBSD way (-5,5000000000,y), so the tests and the debt line would pin values the console does not produce. The trailing%case was not cleanly measured. Please rework against that data, or keep main's throw for what is still unmeasured.core/libs/tests/GuestWideFormatting.cppdefinesCheckGroupingFlag(lines 149 and 247) andCheckSwprintf(lines 189 and 256) twice, andmaincallsCheckSwprintf()twice (lines 351, 354).docs/dev/debt/libc.mdnow has the "narrow printf family" line twice (95, 99) and two "Guest path resolution" lines (104, with a stray.., plus the old one); only the wide printf line should be added.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:07:05Z.
Thanks for the probe and review. It confirms behavior in
libSceLibcInternal.sprx, which differs from this PR’s target (libc.prx), so it does not establish the target formatter’s behavior. I agree the FreeBSD differential results alone do not justify claiming title compatibility; title-side_Printfevidence is still missing. I corrected the rebase mistakes in head9c0f6263c6: the duplicateCheckGroupingFlag/CheckSwprintfdefinitions and call are gone, and the duplicated narrow-printf and guest-path debt entries are removed. The PR description now distinguishes the module evidence and current-head validation. Focused tests still could not be run here; the CMake dependency/configuration blocker is stated above.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T15:08:13Z.
Review: CHANGES_REQUESTED
Thanks, the rebase now looks clean (no duplicate helpers or debt lines). The main blocking point is unchanged:
FormattingWide.cpp:144-157,216-222formats%qd,%D/%O/%Uand unknown conversions the FreeBSD way, andGuestWideFormatting.cpp:213-244plus the debt line pin those values. The only console measurement in this thread (@ionut27001,swprintffromlibSceLibcInternal.sprx, firmware 12.70) prints all of them as literal text (width pads the whole%y/%qd,h/hhdropped), and%m/%lqdprint as text too, while the tests expect an exception for those two. It is a different module than a title'slibc.prx, but it is the only hardware data and it contradicts this code; nothing supports the FreeBSD behaviour on the console.libSceLibcInternal.sprx, not measured onlibc.prx), or drop these cases and keep main's throw until_Printffrom a title'slibc.prxis disassembled or a title reaches them.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:44:33Z.
I updated the implementation and regression cases to match the reported
libSceLibcInternal.sprxpayloadswprintfoutput:%q,%D/%O/%U,%m,%lqd, and unknown conversions are preserved as literal text, with width applied to the full text. Incomplete conversions still fail safely because the trailing-%probe read beyond the format terminator. The secure path remains rejecting these forms because it was not measured. The PR title and description now describe this accurately and explicitly state that this does not establish behavior in a title’s bundledlibc.prx/Dinkumware_Printf.At head
3c74c99b673e1513d51fa9aed48511b7118b9a8a, the focused Linuxguest_wide_formattingtest passes (1/1), conventions pass, andgit diff --checkpasses. The title-side evidence is still absent, as requested in the review; the existing payload measurement is only module-specific evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:46:45Z.
The review follow-up is now rebased onto current
mainatd047690c6391577c9add655ae1dc2ed20df177a8; the rebase completed without conflicts and preserved all five commits’ authorship. On the new head06bd246798, I rebuiltguest_wide_formatting_testsand reranctest -R guest_wide_formatting --output-on-failure(1/1 passed),tools/check_conventions.py(passed), andgit diff --check(passed). The implementation, tests, and debt note reflect the payloadlibSceLibcInternal.sprxmeasurements; titlelibc.prxbehavior remains unverified as stated in the PR description.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:52:35Z.
Thanks for approving. I have kept the module-specific measured behavior and the remaining title
libc.prxevidence limitation explicit in the PR description and follow-up.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T08:29:35Z.
Thanks for the firmware 12.70 payload report. The current PR head already follows the measured literal handling for the reported non-secure wide
swprintfcases and explicitly limits its claim tolibSceLibcInternal.sprx, not a title’s bundledlibc.prx. Your trailing-percent probe shows an out-of-bounds read, so it does not support a deterministic output; the implementation continues to reject an incomplete conversion. I found no additional code change justified by this report. The open title_Printfevidence/rebase review point remains as stated in the latest review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T08:34:14Z.
Rebased the six existing commits onto current upstream
main661f8b71718083fbac1c45b44f5d67dc39cb4624, preserving their original authors. The debt-file conflict retained current-main entries and the PR’s distinction between measured and extrapolated payload behavior. Conventions andgit diff --checkpass on new headf52d991a2d; the focused Linux 1/1 formatting test passed on the prior head06bd246798and has not been rerun after this rebase. No claim is made for titlelibc.prxbehavior or Windows/full-suite validation.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T08:41:12Z.
Final hosted check update for head
f52d991a2df498e341d0ccd7620c80588f97f73d: the Windows relinker CTest has completed successfully. All relinker, register-context, write-watch, ASan, conventions, labels, eligibility and report checks passed. Linux and Windows AGC jobs remain skipped by the PR workflow policy. The focusedguest_wide_formattingtest has still not been rerun after the rebase.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:00:12Z.
I compared the previously tested head
06bd246798with the current PR headf36936b1edbcd1b660a998dfe08680faea458de1:FormattingWide.cppandGuestWideFormatting.cppare byte-for-byte unchanged. The only difference among those paths is the debt documentation. So the focused test result from06bd246798still covers the current implementation and test source; I did not rerun the executable after the rebase.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:56:45Z.
Review: COMMENTED
Replies checked — Fixes checklist line missing, no code finding
The PR body omits the template's
Fixes:checklist line that a reviewer asked for, and the branch merges cleanly with currentupstream/main.What I ran
6de675ebf48b46bb5546a4c8a606e54ce480d08d(OPEN, matches the batch file).gh apicomments, review comments and reviews on #5303, kept only items after 2026-10-27T00:00:07Z from users other than MarcZX10 and bots.gh pr view 5303 --json body,statusCheckRollup.git show 6de675ebf48b46bb5546a4c8a606e54ce480d08d:.github/pull_request_template.md.git merge-tree --write-tree upstream/main 6de675ebf48b46bb5546a4c8a606e54ce480d08d(upstream/main926f7dd492).Results
Fixes:line.github/pull_request_template.mdL16merge-treevs upstream/mainconventionsFindings
- [x] Fixes: none. Confirmed: the body's checklist has noFixes:line. Answer: agreed, add- [x] Fixes: none(this PR closes no issue).GuestWideFormatting.cpp. Stale: the head now merges cleanly with upstream/main. No answer needed beyond the checklist.%q,%D/%O/%Uand unknown conversions is author-reported. Not verified here.Sources
github.com/boykopovar/AnyPS5@6de675ebf4/.github/pull_request_template.md (L16)Not verified