fix(libSceCesCs): convert single-byte characters as measured on a PS5 #10183

Closed
orezraey wants to merge 2 commits from upstream-pr/10183 into main
orezraey commented 2026-10-23 12:12:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T12:12:53Z.


What

sceCesSbcToUtf8 and sceCesUtf8ToSbc used assumed tables and errors. I measured them on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading libSceCesCs.sprx. The sources and console logs are in this gist (pces3 to pces6).

Tables. All 128 high bytes of Cp1252, Cp1251 and Cp1250 match the console, except the bytes the console leaves unassigned (0x805C0020), which we mapped to C1 control characters:

Profile Unassigned bytes
Cp1252 0x81, 0x8D, 0x8F, 0x90, 0x9D
Cp1251 0x98
Cp1250 0x81, 0x83, 0x88, 0x90, 0x98

They are unassigned in both directions now (U+0081 and the others no longer map back), and the MBCS string conversions that share these tables follow. The console's sceCesMbcsStrToUtf8Str also returned 0x805C0020 for Cp1252 byte 0x81.

sceCesSbcToUtf8.

  • The length is cleared to 0 first.
  • A null profile returns 0x805C0004 (we returned 0x805C0001).
  • An unassigned byte returns 0x805C0020 before the output is checked.
  • The length is then set to the UTF-8 size, even when the output is null (0x805C0030) or too small (0x805C0031).

sceCesUtf8ToSbc.

  • The length and output byte are cleared first.
  • A null source or a zero size returns 0x805C0010 (we returned 0x805C0011 for a zero size).
  • Then it decodes the sequence:
    • leads 0xF8–0xFB and 0xFC–0xFD take 5 and 6 bytes;
    • a continuation lead, 0xFE and 0xFF return 0x805C0014 with length 0;
    • a short sequence returns 0x805C0011 with the full length, unless a byte already present is not a continuation byte;
    • a bad continuation byte returns 0x805C0014 with the length set to that byte's index, or the index plus one when the sequence is also short;
    • overlong forms and surrogates return 0x805C0015 (we returned 0x805C0014).
  • The length is reported as above for every case, before the profile is checked.
  • A null profile returns 0x805C0004.
  • Values with no byte in the table, scalars above U+10FFFF included, return 0x805C0020.
  • A null output returns 0x805C0030 last.

The test pins 42 measured sequences with their results and lengths.

Not changed. The console reads any non-null profile pointer as a table: a zero-filled buffer and an EUC-JP profile both converted. Here a pointer that is not one of the three profiles still returns 0x805C0001. Which comes first between a null profile and a scalar above U+10FFFF was not measured. The UTF-8 decoder of the string conversions is unchanged, since only the scalar functions were measured. The debt entries record all of this.

Also found: on this firmware libSceCesCs.sprx does not export the Unicode scalar functions in Unicode.cpp (sceCesUtf8ToUtf32, sceCesUtf16ToUtf8, sceCesUcs2ToUtf8 and the others; pces2), so they could not be measured.

On top of #8923 and #8972. The 27 new profiles keep their tables. The UTF-16 and UTF-32 forms from #8972 share the lookup, so they now answer UNASSIGNED_CODE for the unassigned bytes too, and guest_ces_wide expects that for Cp1251 0x98.

Tested

  • Head after merging main (f26434afa3, with #10706): f7f39ad89c. The test now takes its declarations from libSceCesCs/include/Api.hpp (sceCesRefersUcsProfileCp1250 returns const void* there, so the test casts it). The 14 guest_ces* tests pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); public_headers audit and check_conventions pass.
    Windows 11, MinGW (winlibs).
  • guest_ces checks:
    • every byte of the three profiles: a round trip for assigned bytes, 0x805C0020 with length 0 for the unassigned ones;
    • the 42 measured sceCesUtf8ToSbc sequences;
    • the null, size and output cases above.
  • It fails on main and passes with the change. The ten guest_ces* tests pass three runs in a row.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py lists #8923, #9912 and #9210, which add other code pages and rework sbcToUnicode. They do not change these two functions or these three tables, but whichever merges second needs a rebase. It also lists PRs that touch other lines of docs/dev/debt/libSceCesCs.md.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9175, #10430, #10431 (merge order only: they edit the same lines; this PR is refreshed after them); #10706, #10722, #10739, #10751 edit the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982538985 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10183). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T12:12:53Z. --- ### What `sceCesSbcToUtf8` and `sceCesUtf8ToSbc` used assumed tables and errors. I measured them on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading `libSceCesCs.sprx`. The sources and console logs are in [this gist](https://gist.github.com/orezraey/d17b0c88e64fa0656c9c72fd8abfa29d) (`pces3` to `pces6`). **Tables.** All 128 high bytes of Cp1252, Cp1251 and Cp1250 match the console, except the bytes the console leaves unassigned (`0x805C0020`), which we mapped to C1 control characters: | Profile | Unassigned bytes | |---|---| | Cp1252 | 0x81, 0x8D, 0x8F, 0x90, 0x9D | | Cp1251 | 0x98 | | Cp1250 | 0x81, 0x83, 0x88, 0x90, 0x98 | They are unassigned in both directions now (`U+0081` and the others no longer map back), and the MBCS string conversions that share these tables follow. The console's `sceCesMbcsStrToUtf8Str` also returned `0x805C0020` for Cp1252 byte 0x81. **`sceCesSbcToUtf8`.** - The length is cleared to 0 first. - A null profile returns `0x805C0004` (we returned `0x805C0001`). - An unassigned byte returns `0x805C0020` before the output is checked. - The length is then set to the UTF-8 size, even when the output is null (`0x805C0030`) or too small (`0x805C0031`). **`sceCesUtf8ToSbc`.** - The length and output byte are cleared first. - A null source or a zero size returns `0x805C0010` (we returned `0x805C0011` for a zero size). - Then it decodes the sequence: - leads `0xF8`–`0xFB` and `0xFC`–`0xFD` take 5 and 6 bytes; - a continuation lead, `0xFE` and `0xFF` return `0x805C0014` with length 0; - a short sequence returns `0x805C0011` with the full length, unless a byte already present is not a continuation byte; - a bad continuation byte returns `0x805C0014` with the length set to that byte's index, or the index plus one when the sequence is also short; - overlong forms and surrogates return `0x805C0015` (we returned `0x805C0014`). - The length is reported as above for every case, before the profile is checked. - A null profile returns `0x805C0004`. - Values with no byte in the table, scalars above U+10FFFF included, return `0x805C0020`. - A null output returns `0x805C0030` last. The test pins 42 measured sequences with their results and lengths. **Not changed.** The console reads any non-null profile pointer as a table: a zero-filled buffer and an EUC-JP profile both converted. Here a pointer that is not one of the three profiles still returns `0x805C0001`. Which comes first between a null profile and a scalar above U+10FFFF was not measured. The UTF-8 decoder of the string conversions is unchanged, since only the scalar functions were measured. The debt entries record all of this. Also found: on this firmware `libSceCesCs.sprx` does not export the Unicode scalar functions in `Unicode.cpp` (`sceCesUtf8ToUtf32`, `sceCesUtf16ToUtf8`, `sceCesUcs2ToUtf8` and the others; `pces2`), so they could not be measured. **On top of #8923 and #8972.** The 27 new profiles keep their tables. The UTF-16 and UTF-32 forms from #8972 share the lookup, so they now answer `UNASSIGNED_CODE` for the unassigned bytes too, and `guest_ces_wide` expects that for Cp1251 `0x98`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Head after merging `main` (`f26434afa3`, with #10706): `f7f39ad89c`. The test now takes its declarations from `libSceCesCs/include/Api.hpp` (`sceCesRefersUcsProfileCp1250` returns `const void*` there, so the test casts it). The 14 `guest_ces*` tests pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); `public_headers` audit and `check_conventions` pass. Windows 11, MinGW (winlibs). - `guest_ces` checks: - every byte of the three profiles: a round trip for assigned bytes, `0x805C0020` with length 0 for the unassigned ones; - the 42 measured `sceCesUtf8ToSbc` sequences; - the null, size and output cases above. - It fails on `main` and passes with the change. The ten `guest_ces*` tests pass three runs in a row. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py` lists #8923, #9912 and #9210, which add other code pages and rework `sbcToUnicode`. They do not change these two functions or these three tables, but whichever merges second needs a rebase. It also lists PRs that touch other lines of `docs/dev/debt/libSceCesCs.md`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9175, #10430, #10431 (merge order only: they edit the same lines; this PR is refreshed after them); #10706, #10722, #10739, #10751 edit the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:26:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:26:11Z.

Review: APPROVED


Reviewed the scalar Cp1252/Cp1251/Cp1250 changes at head b41fdbce97. The table entries marked unassigned now fail in both conversion directions, and the UTF-8 decoder’s lengths/errors for truncated sequences, malformed continuations, overlong encodings, surrogates, and out-of-table values match the measurements described. The 42 measured-sequence tests and byte-table round trips are appropriately focused. This exact commit is included in the descendant #10186 C++20 syntax/conventions check; hosted eligibility, conventions, intake, labels and report pass, while product builds are path-skipped. The author reports the ten CES tests passing three consecutive runs. I could not run the executable locally because full CMake configuration is blocked by missing SDL2 development files.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628179627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10183#pullrequestreview-5628179627). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:26:11Z. **Review:** APPROVED --- Reviewed the scalar Cp1252/Cp1251/Cp1250 changes at head b41fdbce977016d911e9e181e5e543d48df0ebb2. The table entries marked unassigned now fail in both conversion directions, and the UTF-8 decoder’s lengths/errors for truncated sequences, malformed continuations, overlong encodings, surrogates, and out-of-table values match the measurements described. The 42 measured-sequence tests and byte-table round trips are appropriately focused. This exact commit is included in the descendant #10186 C++20 syntax/conventions check; hosted eligibility, conventions, intake, labels and report pass, while product builds are path-skipped. The author reports the ten CES tests passing three consecutive runs. I could not run the executable locally because full CMake configuration is blocked by missing SDL2 development files.
MarcZX10 commented 2026-10-23 13:17:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:17:25Z.

Review: CHANGES_REQUESTED


Correction to my prior approval: I had not evaluated the direct overlap with the newly refreshed #10056 head. git merge-tree of #10183 and #10056 reports a content conflict in core/libs/prx/libSceCesCs/Export.cpp, where both alter the single-byte decode/error behavior. Please coordinate the landing order with #10056's author, declare the dependency on the checklist if this PR lands second, and preserve both changes after rebasing. #10185 and #10186 already stack on this conversion work, so keep that dependency chain intact. The exact-head tests previously reviewed remain useful; hosted product checks are path-skipped. This is a keep-both sequencing request, not a request to close either PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628764711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10183#pullrequestreview-5628764711). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T13:17:25Z. **Review:** CHANGES_REQUESTED --- Correction to my prior approval: I had not evaluated the direct overlap with the newly refreshed #10056 head. `git merge-tree` of #10183 and #10056 reports a content conflict in `core/libs/prx/libSceCesCs/Export.cpp`, where both alter the single-byte decode/error behavior. Please coordinate the landing order with #10056's author, declare the dependency on the checklist if this PR lands second, and preserve both changes after rebasing. #10185 and #10186 already stack on this conversion work, so keep that dependency chain intact. The exact-head tests previously reviewed remain useful; hosted product checks are path-skipped. This is a keep-both sequencing request, not a request to close either PR.
MarcZX10 commented 2026-10-23 13:59:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:59:13Z.

Review: APPROVED


Re-review of exact head 8e10ddbb5ce16446c68d71054b6a9ffec76049d6. The previous review asked for an agreed order with #10056 because both changed the single-byte conversion behavior. The authors have now explicitly agreed that #10183/#10184 land first, followed by #10185 and #10186, then #10056; #10056 records its dependency on #10186, and the CES stack PRs record their dependencies. The #10183 checklist correctly remains Depends on: none because it is first.

The implementation diff against current main is limited to Export.cpp, the CES tests, and the CES debt entry; the new commit only merges the same current main base. Exact-head conventions and git diff --check pass. I also ran GCC C++20 -Wall -Wextra -Werror -fsyntax-only on Export.cpp successfully. Hosted eligibility, conventions, labels and report pass; product test/build jobs are skipped by path policy. The author-reported CES test runs remain the available runtime evidence; I could not run the full CMake test locally. The prior overlap blocker is resolved. Approving this exact head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5629283037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10183#pullrequestreview-5629283037). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T13:59:13Z. **Review:** APPROVED --- Re-review of exact head `8e10ddbb5ce16446c68d71054b6a9ffec76049d6`. The previous review asked for an agreed order with #10056 because both changed the single-byte conversion behavior. The authors have now explicitly agreed that #10183/#10184 land first, followed by #10185 and #10186, then #10056; #10056 records its dependency on #10186, and the CES stack PRs record their dependencies. The #10183 checklist correctly remains `Depends on: none` because it is first. The implementation diff against current main is limited to `Export.cpp`, the CES tests, and the CES debt entry; the new commit only merges the same current main base. Exact-head conventions and `git diff --check` pass. I also ran GCC C++20 `-Wall -Wextra -Werror -fsyntax-only` on `Export.cpp` successfully. Hosted eligibility, conventions, labels and report pass; product test/build jobs are skipped by path policy. The author-reported CES test runs remain the available runtime evidence; I could not run the full CMake test locally. The prior overlap blocker is resolved. Approving this exact head.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10183
No description provided.