fix(libSceCesCs): convert single EUC-JP characters as measured on a PS5 #10184

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

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


What

sceCesEucJpToUtf8 and sceCesEucJpToUcs2 used assumed errors and decoded JIS X 0212. I measured them on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading libSceCesCs.sprx. I swept every two-byte input and every 0x8F three-byte input with sceCesEucJpToUcs2. The sources and console logs are in this gist (pces3, pces4, pces5, pces7).

What the console does, and what changes here:

  • Single bytes. Every byte below 0xA0 except 0x0E, 0x8E and 0x8F converts to itself, including 0x80–0x8D and 0x90–0x9F, which we rejected. 0x0E, 0xA0 and 0xFF return 0x805C0014 with length 1; we accepted 0x0E.
  • Half-width katakana. 0x8E with a second byte E0–FE returns 0x805C0020; we returned 0x805C0014.
  • JIS X 0212 is not decoded. A 0x8F form returns 0x805C0020 in the rows X 0212 leaves empty (1, 3–5, 8, 12–15, 78–94) and 0x805C0014 elsewhere, always with length 3. We decoded 6067 X 0212 cells.
  • A zero byte inside a sequence returns 0x805C0014 with the length set to its index. A short sequence returns 0x805C0011 with the full length.
  • Errors and lengths.
    • A null profile returns 0x805C0004; we returned 0x805C0001.
    • A zero size returns 0x805C0010; we returned 0x805C0011.
    • Both length outputs, and the sceCesEucJpToUcs2 output, are cleared first.
    • The source length is then set for every decoded result, errors included.
    • sceCesEucJpToUtf8 sets the UTF-8 length before checking the output, which returns 0x805C0030 or 0x805C0031 and leaves the output untouched.

With the change, the per-lead hashes of result, length and output match the console's for all 256 leads and all 256 0x8F second bytes. The JIS X 0208 table (including NEC row 13 and the IBM extensions in rows 89–92) was already right.

Not changed. The console reads any other profile pointer as a sheet; with the Cp1252 profile it faulted. Here a pointer that is not an EUC-JP profile still returns 0x805C0001. The MBCS string conversions keep decoding JIS X 0212, although the console's sceCesMbcsStrToUtf8Str rejected 8F A2 AF with 0x805C0014; their errors and partial output are a separate change. The debt entry records both. The strict JIS X 0208 profiles that main added later were not measured: with them, both functions keep the earlier path through decodeMbcs, so their errors leave the outputs unchanged.

On top of #8967 and #8972. The measured byte rules apply only to sceCesEucJpToUcs2 and sceCesEucJpToUtf8, through decodeEucJpScalar. sceCesEucJpToUtf16 and sceCesEucJpToUtf32 from #8967 still decode through the unchanged decodeMbcs, so this PR does not change them.

Tested

  • Head after merging main (f26434afa3, with #10706): 1f9a014195. The test now takes its declarations from libSceCesCs/include/Api.hpp instead of its own extern "C" block. 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 pins the FNV hash of result, length and output over all 65536 two-byte inputs and all 65536 0x8F three-byte inputs. It also checks the null, size, output and length cases above. The JIS X 0212 round trip now goes through the string conversions.
  • guest_ces_unicode checks the single bytes, the half-width katakana and every JIS X 0208 cell with the measured lengths.
  • Both fail on main and pass with the change. The fourteen guest_ces* tests pass three runs in a row, on Windows and on Linux (WSL, GCC).
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py lists:
    • #8923, #9912 and #9210 (other code pages in Export.cpp and GuestCes.cpp), none of which changes these functions;
    • #6044, which moves test files.

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: #10706 (merge order only: they edit the same lines; this PR is refreshed after them)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982539845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10184). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T12:12:57Z. --- ### What `sceCesEucJpToUtf8` and `sceCesEucJpToUcs2` used assumed errors and decoded JIS X 0212. I measured them on a retail PS5 (firmware 13.60) with homebrew probes, from a payload process loading `libSceCesCs.sprx`. I swept every two-byte input and every `0x8F` three-byte input with `sceCesEucJpToUcs2`. The sources and console logs are in [this gist](https://gist.github.com/orezraey/2c47c81c27ef8879676e7e4a74cb927a) (`pces3`, `pces4`, `pces5`, `pces7`). What the console does, and what changes here: - **Single bytes.** Every byte below 0xA0 except 0x0E, 0x8E and 0x8F converts to itself, including 0x80–0x8D and 0x90–0x9F, which we rejected. 0x0E, 0xA0 and 0xFF return `0x805C0014` with length 1; we accepted 0x0E. - **Half-width katakana.** `0x8E` with a second byte E0–FE returns `0x805C0020`; we returned `0x805C0014`. - **JIS X 0212 is not decoded.** A `0x8F` form returns `0x805C0020` in the rows X 0212 leaves empty (1, 3–5, 8, 12–15, 78–94) and `0x805C0014` elsewhere, always with length 3. We decoded 6067 X 0212 cells. - **A zero byte inside a sequence** returns `0x805C0014` with the length set to its index. A short sequence returns `0x805C0011` with the full length. - **Errors and lengths.** - A null profile returns `0x805C0004`; we returned `0x805C0001`. - A zero size returns `0x805C0010`; we returned `0x805C0011`. - Both length outputs, and the `sceCesEucJpToUcs2` output, are cleared first. - The source length is then set for every decoded result, errors included. - `sceCesEucJpToUtf8` sets the UTF-8 length before checking the output, which returns `0x805C0030` or `0x805C0031` and leaves the output untouched. With the change, the per-lead hashes of result, length and output match the console's for all 256 leads and all 256 `0x8F` second bytes. The JIS X 0208 table (including NEC row 13 and the IBM extensions in rows 89–92) was already right. **Not changed.** The console reads any other profile pointer as a sheet; with the Cp1252 profile it faulted. Here a pointer that is not an EUC-JP profile still returns `0x805C0001`. The MBCS string conversions keep decoding JIS X 0212, although the console's `sceCesMbcsStrToUtf8Str` rejected `8F A2 AF` with `0x805C0014`; their errors and partial output are a separate change. The debt entry records both. The strict JIS X 0208 profiles that `main` added later were not measured: with them, both functions keep the earlier path through `decodeMbcs`, so their errors leave the outputs unchanged. **On top of #8967 and #8972.** The measured byte rules apply only to `sceCesEucJpToUcs2` and `sceCesEucJpToUtf8`, through `decodeEucJpScalar`. `sceCesEucJpToUtf16` and `sceCesEucJpToUtf32` from #8967 still decode through the unchanged `decodeMbcs`, so this PR does not change them. ### 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): `1f9a014195`. The test now takes its declarations from `libSceCesCs/include/Api.hpp` instead of its own `extern "C"` block. 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` pins the FNV hash of result, length and output over all 65536 two-byte inputs and all 65536 `0x8F` three-byte inputs. It also checks the null, size, output and length cases above. The JIS X 0212 round trip now goes through the string conversions. - `guest_ces_unicode` checks the single bytes, the half-width katakana and every JIS X 0208 cell with the measured lengths. - Both fail on `main` and pass with the change. The fourteen `guest_ces*` tests pass three runs in a row, on Windows and on Linux (WSL, GCC). - `tools/check_conventions.py` passes. - `tools/pr_overlap.py` lists: - #8923, #9912 and #9210 (other code pages in `Export.cpp` and `GuestCes.cpp`), none of which changes these functions; - #6044, which moves test files. ### 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: #10706 (merge order only: they edit the same lines; this PR is refreshed after them) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:25:32 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the single-character EUC-JP decoder change at head e04647b318. The measured length/error handling for single bytes, half-width forms, zero bytes, short sequences, and JIS X 0212 rows is reflected in the implementation and full-input hash regressions. The branch reports the ten focused CES tests passing three consecutive runs; eligibility, conventions, intake, labels and report checks pass, while product jobs are path-skipped. The implementation and tests also pass C++20 syntax checks in the descendant #10186 tree. I could not run the executable locally because the full project configure is blocked by missing SDL2 development files.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628172575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10184#pullrequestreview-5628172575). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:25:32Z. **Review:** APPROVED --- Reviewed the single-character EUC-JP decoder change at head e04647b31870414c3c778a1e8fb0cf3f5c39c31d. The measured length/error handling for single bytes, half-width forms, zero bytes, short sequences, and JIS X 0212 rows is reflected in the implementation and full-input hash regressions. The branch reports the ten focused CES tests passing three consecutive runs; eligibility, conventions, intake, labels and report checks pass, while product jobs are path-skipped. The implementation and tests also pass C++20 syntax checks in the descendant #10186 tree. I could not run the executable locally because the full project configure is blocked by missing SDL2 development files.

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