feat(libSceCesCs): select the single-byte set of an MBCS profile and a replacement character for a context #10431
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10431"
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 rooklz on 2026-10-24T00:04:52Z.
What
Eight libSceCesCs exports that still threw now work: the single-byte-set selectors
sceCesSJisUcsProfileSetSbcs,sceCesEucJpUcsProfileSetSbcs,sceCesEucKrUcsProfileSetSbcs,sceCesUhcUcsProfileSetSbcs,sceCesEucCnUcsProfileSetSbcsandsceCesGbUcsProfileSetSbcs, and the context setterssceCesMbcsUcsSetMbcsReplacementCharCodeandsceCesMbcsUcsSetMbcsReplacementCharUCode. Signatures follow the Orbital type database:int (union* p, const SceCesSbcsUcsProfile* sbcs)andint (union* context, uint32_t code).A selector records the chosen single-byte profile in the eighth byte of the sheet's tag: the tags the initialisers write are seven identifying characters and a zero byte, the selectors store a 1-based index into the single-byte profile table in the eighth, validated before use, and re-initialising a sheet clears it. Nothing is written to the sheet beyond the eight bytes the library already wrote, and a sheet copied by value keeps its selection. Family classification uses the seven-byte sheet-tag prefix only for the mutable MBCS sheets whose selector writes that eighth byte; tags whose eighth byte carries identity, the three ISO-2022 profiles and the two JIS 2004 profiles, are matched over all eight bytes, so the RFC 1468, CP50221 and CP50222 profiles stay distinguishable.
The behaviour is measured on a PS5, with a homebrew payload that loads the console's
libSceCesCs.sprxand runs each of the six selectors with eight single-byte profiles, decoding0x00-0x7Fand encoding the affected code points after each, plus both replacement setters with valid and invalid values. On the console:0x805C0004.0x5Cis ¥ and0x7Eoverline both ways, U+007E is unassigned, and the JIS profiles encode U+005C as cell0x2140(81 5Fin Shift-JIS,A1 C0in EUC-JP); KS X 1003 and GB 1988 work the same way with ₩ at0x5Cand ¥ at0x24, leaving U+005C and U+0024 unassigned. Shift-JIS loses its katakana half under ASCII and Roman.CharCodeanswers0x805C0015for a value past one lead and trail byte (0x100,0x10000);CharUCodeanswers0x805C0014past U+10FFFF,0x805C0015for a surrogate and0x805C0020for a character the profile cannot encode (U+FFFD in every profile measured). The string conversions measured (sceCesUtf8StrToMbcsStr,sceCesMbcsStrToUtf8Str) still answer their errors with a replacement set, so the conversions here no longer use it; earlier heads wrote it in place of the unmappable character.The console's sheet and context layouts are not known, which is why neither is extended: the selection is kept in the tag's eighth byte and the replacement in a table keyed by the context's address (
ContextInitclears it andContextInitCopycopies it). The GB 18030 profiles withsceCesGbUcsProfileSetSbcsare not measured.sceCesGbUcsProfileSet4ByteCharRange,sceCesGbUcsProfileSetUdaMappingandsceCesIso2022JpUcsProfileSetSbcskeep throwing.Tested
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, GCC 13.3, Release):ctest -j6passes 542/542, includinggit diff --checkandcheck_conventions.py --base upstream/main.guest_ces*source linked against thisExport.cppexits 0:guest_ces,guest_ces_dbcs,guest_ces_jis2004,guest_ces_iso646,guest_ces_iso2022,guest_ces_mbc,guest_ces_chinese,guest_ces_wide,guest_ces_japanese,guest_ces_unicode, andguest_ces_setters.guest_ces_iso2022passes the existing RFC 1468, CP50221 and CP50222 cases, including the CP50221ESC ( I 36 ESC ( Bversus CP50222SO 36 SI ESC ( BKatakana distinction, so the full-width ISO-2022 tag matching is preserved.guest_ces_settersselects the single-byte set on Shift-JIS, EUC-JP, EUC-KR, UHC, EUC-CN, GBK and both GB 18030 variants after the tag byte is written, copies a selected sheet by value and converts through the copy, and re-initialises a copy without affecting the original; it also covers the replacement context andsceCesMbcsUcsContextInitCopy.f49438e9b2(verify run on my fork): the Windows full build (Server 2025, WinLibs GCC 15.2.0, Release) compiles everything and passes all eighteenguest_ces*tests; the Linux full build (Ubuntu 24.04, GCC, Release, lavapipe) passes everyguest_ces*test, its one failure beingagc_driver_sgpr_pattern_fill_keys, whichmainfails on that runner. A rerun on this head follows.pr_overlap.pyreports only the sharedlibSceCesCsfiles of the other open CesCs PRs.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 MarcZX10 on 2026-10-24T00:14:33Z.
Review: CHANGES_REQUESTED
I found one blocking ABI/memory-safety gap at this head. The profile sheet was previously initialized and consumed through its 8-byte tag, but this change now clears bytes 8–15 in every , reads in , and writes in each . These APIs accept only an opaque pointer, so there is no size argument or validation that the caller supplied 16 bytes. The PR description explicitly says the console sheet layout is unknown; the tests allocate oversized arrays and therefore do not establish that contract. A caller with an 8-byte sheet can now be overwritten by initialization or read out of bounds during conversion. Also, a nonzero unvalidated index in byte 8 can index past at . Please establish the real sheet extent/layout from a primary source or console measurement before using those bytes, and validate the stored index before dereferencing it. Until the sheet ABI is established, these selectors should not mutate or consume speculative trailing storage.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T00:14:40Z.
Review: CHANGES_REQUESTED
I found one blocking ABI/memory-safety gap at this head. The profile sheet was previously initialized and consumed through its 8-byte tag, but this change now clears bytes 8–15 in every profile initializer, reads profile byte 8 in sheetSbcs, and writes sheet byte 8 in each single-byte selector. These APIs accept only an opaque pointer, so there is no size argument or validation that the caller supplied 16 bytes. The PR description explicitly says the console sheet layout is unknown; the tests allocate oversized arrays and therefore do not establish that contract. A caller with an 8-byte sheet can now be overwritten by initialization or read out of bounds during conversion. Also, a nonzero unvalidated index in byte 8 can index past the profile table. Please establish the real sheet extent/layout from a primary source or console measurement before using those bytes, and validate the stored index before dereferencing it. Until the sheet ABI is established, these selectors should not mutate or consume speculative trailing storage.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T00:18:44Z.
Review: CHANGES_REQUESTED
The new head removes the out-of-bounds access, which resolves the memory-safety finding from my earlier review. I still cannot approve the selector behavior: the side table makes the selected set depend on the profile sheet's address, and the author confirms in the PR description/debt that copying a sheet by value loses the selection. These are caller-owned profile sheets with value tags; there is no evidence that the console API makes a sheet address-bound or forbids copies. The tests exercise only the original address. This leaves a known, behaviorally significant case unsupported rather than implementing the general function behavior required by CONTRIBUTING.md. Please establish the sheet lifecycle/copy contract from a primary source or console measurement and test it; otherwise keep the selectors fail-fast until that contract is known. The replacement context has an explicit ContextInitCopy path, but the sheet selection does not have an equivalent copy operation.
I reran diff-check and the conventions check at head 61dc88f; both pass. This is a behavior/contract blocker, not a build finding.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T00:27:45Z.
Review: CHANGES_REQUESTED
Thanks for replacing the address-keyed sheet selection with the existing eighth tag byte; that resolves the copy-by-value limitation I raised. I found a regression in the new tag matching that needs correction.
sceCes*UcsProfileSetSbcswrites the profile index tosheet[7], but several consumers still compare all eight tag bytes against a zero-terminated tag. In this head,isEucCn,isGbk,gb18030Tables,isEucKr,isUhcandisBig5usememcmp(..., sizeof(TAG)). After a selector succeeds, the nonzero byte 7 makes those predicates false.isSheetthen stops recognizing the sheet, sosheetSbcsignores the selected set; for GB18030,gb18030Tablessimilarly stops recognizing the codec. The EUC-JP and Shift-JIS predicates use the shortened seven-bytehasTag, which is why those do not have this specific issue.Please make all affected family predicates consistently compare the seven-byte family prefix (while retaining distinct prefixes), and add/adjust assertions showing selected SBCS behavior for EUC-KR, UHC, EUC-CN, GBK and both GB18030 variants after setting the selector. The current
GuestCesProfileSetterstests contain those cases, so please also reconcile them with the reported container pass: as written against this head, the full-width comparisons appear to reject the just-mutated tag.The exact diff-check and current-main conventions check pass. I did not run the product test locally; CMake configuration is blocked here by the unavailable SDL2 package configuration.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T00:33:28Z.
Review: APPROVED
Reviewed the current head
f49438e9b2b023ec3c771d710760c88d39fa19d0. The earlier copy-by-value and seven-byte family-tag findings are addressed: profile selection is carried in the existing tag byte, all affected codec predicates use the common family matcher, and tests exercise SBCS selection after mutation across EUC-KR, UHC, EUC-CN, GBK and both GB18030 variants. The replacement-context copy path is also covered. I rangit diff --checkand the current-main conventions check successfully. Hosted eligibility, conventions, labels, and report pass; product build jobs are skipped by workflow policy. The PR declares its dependency on #10430.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:14:00Z.
Review: APPROVED
Re-checked — approved
I rechecked the current head
40b182df7b37ed9abdfa92a51671c46ac69cc021against my earlier review. The profile-sheet tag logic is unchanged from the previously approvedf49438e9b2implementation; the later changes restack the feature, add the canonicalApi.hppinclude in the test, update the debt text, and restore the SPIRV gitlink to the current-main value. This preserves the bounds-safe eight-byte tag and copy-by-value selection behavior that resolved my earlier findings.The author reports the focused selector tests on the feature head, including the GB 18030-2000 case; hosted Windows and conventions/eligibility/label checks pass. Linux product CI is skipped. I did not rerun the console differential or local tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T22:29:45Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The rebase made the shared profile-tag matcher ignore the byte that distinguishes the three ISO-2022 profiles, so current ISO-2022 behavior is no longer preserved.
What I ran
Reviewed head
2e31923fc981b65eb3920a2391318104de6549b3against base1bc97b9527eaf6b56681cd3465bca67b75329161. The local merge preview against currentmainwas clean. Environment: Debian Linux x86_64, Python 3.11.2; I did not compile or build.I inspected the exact-head diff, the exact-head ISO-2022 tag checks, and the current-base ISO-2022 regression cases. The author's reported
guest_ces_setters2/2 result is separate evidence and does not exercise the ISO-2022 cases below.Results
library-portability,report, andeligibilitypassed; Linux and specialized build jobs were skipped; Windows, conventions, and labels were still queued at the last check.Unedited output — conventions
Unedited output — merge preview
Negative control
Findings
Blocking
hasTagcompares only the first seven bytes. The RFC 1468, CP50221, and CP50222 tags all share those seven bytes (ISO2022) and differ in byte eight. ConsequentlyisIso2022Rfc1468andiso2022ShiftsKatakanamatch all three profiles. For example, the existing CP50221 case expectsESC ( I 36 ESC ( B(7 bytes), while CP50222 expectsSO 36 SI ESC ( B(6 bytes); the current matcher makes the profiles indistinguishable and breaks the existing profile-specific contract. Keep full-width matching for tags whose last byte carries identity, and use a separate shortened comparison only for mutable MBCS sheet tags.Non-blocking
None.
Sources
hasTagcomparison at the reviewed headNot verified
To get this to a good state
Keep ISO-2022 profile identity checks over all eight tag bytes, and limit seven-byte matching to the MBCS profiles whose selector stores data in byte eight. Run
guest_ces_iso2022andguest_ces_setterson the corrected head; I will rerun the same source and CI checks against that head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T22:58:12Z.
Review: APPROVED
Re-checked — new head, looks good
The new head restores the full eight-byte identity check for ISO-2022 tags and confines shortened matching to mutable MBCS sheet tags, resolving the regression from my previous review.
What I ran
Reviewed head
dc9605e0c1199b4a60bab42229791972d6e7db6aagainst currentmain7a5d9bf02af636382aec927593b1a5867899ed0f; the merge preview is clean. Environment: Debian Linux x86_64, glibc 2.36, Python 3.11.2, GCC/G++ 12.2.0. I did not build locally.Results
settersandsetters_modulevariants in the CMake loop. The test-quality helper's literal-path warning is a heuristic false positive because the source path is formed with${LIBS_INCLUDE_DIR}.Unedited check output
Conventions:
ABI audit:
Windows CTest:
Precheck helper availability:
Negative control
Findings
Blocking
None found in the reviewed head.
Non-blocking
Linux and specialized product jobs were skipped by hosted CI; see Not verified.
Sources
hasTagand separate sheet-tag matcher at this headNot verified
To get this to a good state
No further change is needed for the reviewed regression. If the head changes, I will rerun these checks against the new head.