fix(libSceCesCs): refuse the Cp1254 and Cp1258 holes and UTF-32 surrogates as a PS5 does #13848

Closed
zaryabzip wants to merge 0 commits from upstream-pr/13848 into main
zaryabzip commented 2026-10-31 09:26:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T09:26:07Z.


What

Two single-byte conversion answers now match what @rooklz measured on a PS5. That sweep converted every byte through sceCesSbcToUtf32 and every BMP scalar through sceCesUtf32ToSbc, for every single-byte profile:

PS5 main before
Cp1254 bytes 81 8D 8E 8F 90 9D 9E 0x805C0020 both ways C1 code points (U+0081…)
Cp1258 bytes 81 8A 8D 8E 8F 90 9A 9D 9E 0x805C0020 both ways C1 code points
sceCesUtf32ToSbc with a surrogate, every single-byte profile 0x805C0015 (ILLEGAL_CODE) 0x805C0014 (INVALID_ENCODE)

@BunnyFl's 13.42 run of the module gives the same Cp1254 and Cp1258 bytes. #10185 already made Cp1250 to 1252 answer this way. The same sweep found the ISO 8859, PC code page and KOI8 tables matching byte for byte, and Cp1256 with no holes.

  • Tables: the 16 bytes become the table's existing 0xFFFF (unassigned) marker. The reverse lookup then refuses U+0081 and the others too.
  • Surrogate: sceCesUtf32ToSbc answers 0x805C0015 after its existing profile and destination checks. sceCesUcs2ToSbc and the big- and little-endian UTF-32 forms share the helper but weren't measured, so they keep 0x805C0014, and GuestCesWide.cpp's Ucs2ToSbc(0xD800) row is unchanged.
  • Debt: the single-byte entry no longer says these holes map to C1. A new entry records the bytes, the surrogate answer and both sources, and says the MBCS context conversions and the other UTF-32 and UCS-2 forms weren't measured.

No function changes count.

Overlap: #10056 (approved, older) also rewrites the single-byte debt line, which this has to change because it says the holes map to C1. #10056 goes first and I'll rebase this onto it. git merge-tree merges this cleanly with every other open pull request that merges with main, including #13573, which edits the debt lines just above.

Tests:

  • GuestCes.cpp's CheckSingleByteProfiles sweep now expects 0x805C0020 from sceCesSbcToUtf32 and sceCesUtf32ToSbc at those bytes, and the old round trip everywhere else.
  • GuestCesWide.cpp adds sceCesUtf32ToSbc(0xD800) with Cp1252 and (0xDFFF) with Cp1254.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with 5f4b1c401e merged into main d93ebe62d9. The head 3c478fe2a4 differs from it only in where the surrogate note sits in the debt file.

  • No warnings in Export.cpp, SingleByte.hpp, GuestCes.cpp or GuestCesWide.cpp.
  • ctest -R guest_ces: 20 of 20 pass on both hosts, the module builds included; guest_ces passes 3 of 3 on --repeat until-fail:3.
  • Baseline: on that main with only the two test files, guest_ces and guest_ces_module abort at the first hole (Cp1254 byte 0x81 decodes to a C1 code point), and guest_ces_wide and guest_ces_wide_module at the first surrogate row (0x805C0014), on both hosts (Windows exit 0xc0000409, Linux SIGABRT).
  • tools/check_conventions.py passes.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5096305919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13848). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T09:26:07Z. --- ### What Two single-byte conversion answers now match what @rooklz [measured on a PS5](https://github.com/boykopovar/AnyPS5/pull/10183#issuecomment-6389941634). That sweep converted every byte through `sceCesSbcToUtf32` and every BMP scalar through `sceCesUtf32ToSbc`, for every single-byte profile: | | PS5 | `main` before | |---|---|---| | Cp1254 bytes `81 8D 8E 8F 90 9D 9E` | `0x805C0020` both ways | C1 code points (`U+0081`…) | | Cp1258 bytes `81 8A 8D 8E 8F 90 9A 9D 9E` | `0x805C0020` both ways | C1 code points | | `sceCesUtf32ToSbc` with a surrogate, every single-byte profile | `0x805C0015` (`ILLEGAL_CODE`) | `0x805C0014` (`INVALID_ENCODE`) | @BunnyFl's [13.42 run of the module](https://github.com/boykopovar/AnyPS5/pull/9912#issuecomment-6403897082) gives the same Cp1254 and Cp1258 bytes. #10185 already made Cp1250 to 1252 answer this way. The same sweep found the ISO 8859, PC code page and KOI8 tables matching byte for byte, and Cp1256 with no holes. - **Tables:** the 16 bytes become the table's existing `0xFFFF` (unassigned) marker. The reverse lookup then refuses `U+0081` and the others too. - **Surrogate:** `sceCesUtf32ToSbc` answers `0x805C0015` after its existing profile and destination checks. `sceCesUcs2ToSbc` and the big- and little-endian UTF-32 forms share the helper but weren't measured, so they keep `0x805C0014`, and `GuestCesWide.cpp`'s `Ucs2ToSbc(0xD800)` row is unchanged. - **Debt:** the single-byte entry no longer says these holes map to C1. A new entry records the bytes, the surrogate answer and both sources, and says the MBCS context conversions and the other UTF-32 and UCS-2 forms weren't measured. No function changes count. Overlap: #10056 (approved, older) also rewrites the single-byte debt line, which this has to change because it says the holes map to C1. #10056 goes first and I'll rebase this onto it. `git merge-tree` merges this cleanly with every other open pull request that merges with `main`, including #13573, which edits the debt lines just above. Tests: - `GuestCes.cpp`'s `CheckSingleByteProfiles` sweep now expects `0x805C0020` from `sceCesSbcToUtf32` and `sceCesUtf32ToSbc` at those bytes, and the old round trip everywhere else. - `GuestCesWide.cpp` adds `sceCesUtf32ToSbc(0xD800)` with Cp1252 and `(0xDFFF)` with Cp1254. ### 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. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with 5f4b1c401e merged into `main` d93ebe62d9. The head 3c478fe2a4 differs from it only in where the surrogate note sits in the debt file. - No warnings in `Export.cpp`, `SingleByte.hpp`, `GuestCes.cpp` or `GuestCesWide.cpp`. - `ctest -R guest_ces`: 20 of 20 pass on both hosts, the module builds included; `guest_ces` passes 3 of 3 on `--repeat until-fail:3`. - Baseline: on that `main` with only the two test files, `guest_ces` and `guest_ces_module` abort at the first hole (Cp1254 byte 0x81 decodes to a C1 code point), and `guest_ces_wide` and `guest_ces_wide_module` at the first surrogate row (`0x805C0014`), on both hosts (Windows exit 0xc0000409, Linux SIGABRT). - `tools/check_conventions.py` passes. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)

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!13848
No description provided.