fix(libSceCesCs): terminate and count MBCS string conversions as measured on a PS5 #10185
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10185"
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 orezraey on 2026-10-23T12:13:02Z.
What
The MBCS string conversions (
sceCesUtf8StrToMbcsStr,sceCesUcs2StrToMbcsStr,sceCesMbcsStrToUtf8Str,sceCesMbcsStrToUcs2Strand theirGet*Lenforms) wrote no terminator and set no length on an error. I measured them on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loadinglibSceCesCs.sprx, with the Cp1252 and EUC-JP profiles. The sources and console logs are in this gist (pces8,pces9,pces10).On the console:
ABCinto 3 bytes givesAB, a terminator and0x805C0031with lengths 2 and 2. With a capacity of 0, nothing is written.A, 0x81,Bin Cp1252 returns0x805C0020with lengths 1 and 1 and the outputA, terminator.0x805C0001), source (0x805C0010), output (0x805C0030).sceCesUtf8ToSbcdoes: overlong forms and surrogates give0x805C0015, and a zero byte inside a sequence is an invalid byte.0x805C0015.sceCesEucJpToUcs2does, so8F A2 AFgives0x805C0014.0x805C0020with the EUC-JP profile. We encoded them as0x8Ftriples.This PR implements all of the above with one conversion loop shared by the eight functions.
sceCesMbcsUcsContextInitwith a null profile now returns0x805C0001as well, as the console did; before, it stored the null profile.Not changed, recorded in the debt file. The console encodes U+00A5, U+203E and U+0080–U+009F to EUC-JP bytes where we answer
UNASSIGNED_CODE. Its Shift-JIS encoder answers0x805C0024for U+0080–U+009F and accepts the JIS forms of a few Microsoft characters. These table choices are a separate change. A zero-filled context converted nothing and returned 0 on the console; here it returns0x805C0001.Depends on the two scalar PRs, for
decodeScalarUtf8anddecodeEucJpScalar. This branch carries their commits until they merge.On top of #8967 and #8972. The UTF-16 and UTF-32 string forms from #8972 now run through the same loop, so they stop, terminate and count the same way.
sceCesUtf8ToSJis,sceCesUtf8ToEucJpand the GBK and EUC-CN forms from #8976 decode UTF-8 likesceCesUtf8ToSbc. JIS X 0212 is neither decoded nor encoded, as measured, so twoguest_ces_japanesechecks that expected0x8FB0A1for U+4E02 now expectINVALID_ENCODEandUNASSIGNED_CODE.Tested
main(f26434afa3, with #10706):4c3c3231d6. The test now takes its declarations fromlibSceCesCs/include/Api.hpp(sceCesRefersUcsProfileCp1250returnsconst void*there, so the test casts it). The 14guest_ces*tests pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC);public_headersaudit andcheck_conventionspass.Windows 11, MinGW (winlibs).
guest_ceschecks:Get*Lenforms;guest_ces_dbcshad output buffers with no room for a terminator. It now keeps that room; before, it passed without converting anything.guest_ces*tests pass three runs in a row.tools/check_conventions.pypasses.tools/pr_overlap.pylists #8923, #9912 and #9210 (other code pages inExport.cppand the tests) and #6044 (moves test files).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)GuestCes.cpp(merge order only); #10722, #10739, #10751 edit the same lines too (merge order only)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:25:01Z.
Review: APPROVED
Reviewed the MBCS conversion-loop change at head
00b45d43de, stacked on #10183 and #10184. The shared loop clears lengths and initializes the terminator before validation, preserves converted prefixes on error, reserves terminator capacity, and handles sourceMax=0 as the measured NUL-terminated mode. UTF-8/EUC-JP/UCS-2 decode paths and the new focused cases align with the described firmware measurements. This exact head is included in the descendant #10186 syntax check; its hosted eligibility, conventions, intake, labels and report checks pass, while product builds are path-skipped. The author reports the ten focused tests passing three consecutive runs on Windows. I could not execute them here because full CMake configuration is blocked by the missing SDL2 development package. The declared dependencies match the branch stack.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:59:13Z.
Review: APPROVED
Re-review of exact current head
e4ed848821e95fb162923e68991d6c32d9d5cfb8. The source/test/debt diff against current main is unchanged by this head's merge-main refresh. Its checklist records the agreed #10183/#10184 prerequisites, and #10186 records #10185 as its prerequisite; #10056 then depends on #10186. Exact-head repository conventions andgit diff --checkpass, and GCC C++20 strict syntax-only compilation of the CES export passes. Hosted eligibility, conventions, labels and report pass; product test/build jobs are path-skipped. The author reports the focused CES tests passing three runs; no full runtime suite was available locally. Approving this exact head in the agreed stack order.