fix(libSceCesCs): report the length of a rejected MBCS character as the console does #10722

Merged
rooklz merged 1 commit from upstream-pr/10722 into main 2026-10-25 23:10:42 +00:00
rooklz commented 2026-10-24 19:46:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-24T19:46:15Z.


What

A rejected multibyte character left every output alone. On a PS5 it reports its length and clears the character. I measured it with homebrew payloads that load the console's libSceCesCs.sprx, over every one- and two-byte sequence of all 15 MBCS profiles with sceCesMbcToUtf32, every 0x8F-led three-byte and every 0x81 0x30-led three- and four-byte sequence, and the same two-byte sweep through sceCesMbcTo{Ucs2,Utf8,Utf16} and each encoding's own To{Ucs2,Utf8,Utf16,Utf32} for eight profiles. Every form agreed with sceCesMbcToUtf32 on the result and the length for all 65792 inputs. On an error the console:

  • reports the length: the bytes a truncated sequence needs (0x805C0011, 4 for 0x81 0x30 in GB 18030), one byte for a bad lead, the bytes before a NUL found after the lead (checked byte by byte, before more bytes are asked for), and the whole sequence for a bad or unassigned trail;
  • clears the character: a UCS-2 or UTF-32 output becomes 0, and the UTF-8 and UTF-16 forms report 0 units and leave their buffer alone.

The decoders now set that length on each error path, and the single-character wrappers store it with the cleared output. Argument errors keep the outputs untouched. sceCesEucJpToUcs2 and sceCesEucJpToUtf8 are left out: #10184 measured those two on a PS5 and changes them, with the same length rule.

Tested

  • guest_ces_mbc: 28 rejected sequences across Shift-JIS, EUC-JP, GBK, GB 18030, UHC and Big5, each through all eight sceCesMbcTo* forms, with the length and output the console gives; these values were looked up in the console dump.
  • guest_ces_chinese, guest_ces_dbcs, guest_ces_japanese: the checks that expected untouched outputs after a rejected character now expect the console's length and cleared character. The other guest_ces* tests pass.
  • macOS (Apple clang 21, x86-64): all seven guest_ces* sources pass against this Export.cpp; a harness built from it matches the console dump's result and length for every recorded sequence apart from table and single-byte differences that are other PRs' topics.
  • Hosted Linux runner, head 67e4ffb032 (same tree as the verified 2f81a7927f; verify run on my fork; Ubuntu 24.04, GCC, Release, lavapipe): every guest_ces* test passes. Its one failure, pr_overlap_encoding, fails the same way on main on that runner (the base side of the same run).
  • check_conventions.py passes. pr_overlap.py reports #9175, #9912, #10056, #10183, #10185, #10186, #10426, #10428, #10706 and #10718 on nearby lines of Export.cpp, the guest_ces* tests or the debt file; none changes these error paths (#10706 moves declarations into export headers).

Merge order: this lands before #10718, which is rebased onto it (both change the Shift-JIS and EUC-JP decode paths in Export.cpp and the same GuestCesJapanese.cpp checks).

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; #10184 changes the EUC-JP scalar forms with the same rule
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4998570988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10722). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-24T19:46:15Z. --- ### What A rejected multibyte character left every output alone. On a PS5 it reports its length and clears the character. I measured it with homebrew payloads that load the console's `libSceCesCs.sprx`, over every one- and two-byte sequence of all 15 MBCS profiles with `sceCesMbcToUtf32`, every `0x8F`-led three-byte and every `0x81 0x30`-led three- and four-byte sequence, and the same two-byte sweep through `sceCesMbcTo{Ucs2,Utf8,Utf16}` and each encoding's own `To{Ucs2,Utf8,Utf16,Utf32}` for eight profiles. Every form agreed with `sceCesMbcToUtf32` on the result and the length for all 65792 inputs. On an error the console: - **reports the length**: the bytes a truncated sequence needs (`0x805C0011`, 4 for `0x81 0x30` in GB 18030), one byte for a bad lead, the bytes before a NUL found after the lead (checked byte by byte, before more bytes are asked for), and the whole sequence for a bad or unassigned trail; - **clears the character**: a UCS-2 or UTF-32 output becomes 0, and the UTF-8 and UTF-16 forms report 0 units and leave their buffer alone. The decoders now set that length on each error path, and the single-character wrappers store it with the cleared output. Argument errors keep the outputs untouched. `sceCesEucJpToUcs2` and `sceCesEucJpToUtf8` are left out: #10184 measured those two on a PS5 and changes them, with the same length rule. ### Tested - `guest_ces_mbc`: 28 rejected sequences across Shift-JIS, EUC-JP, GBK, GB 18030, UHC and Big5, each through all eight `sceCesMbcTo*` forms, with the length and output the console gives; these values were looked up in the console dump. - `guest_ces_chinese`, `guest_ces_dbcs`, `guest_ces_japanese`: the checks that expected untouched outputs after a rejected character now expect the console's length and cleared character. The other `guest_ces*` tests pass. - macOS (Apple clang 21, x86-64): all seven `guest_ces*` sources pass against this `Export.cpp`; a harness built from it matches the console dump's result and length for every recorded sequence apart from table and single-byte differences that are other PRs' topics. - Hosted Linux runner, head `67e4ffb032` (same tree as the verified `2f81a7927f`; [verify run on my fork](https://github.com/rooklz/AnyPS5/actions/runs/40125640128); Ubuntu 24.04, GCC, Release, lavapipe): every `guest_ces*` test passes. Its one failure, `pr_overlap_encoding`, fails the same way on `main` on that runner (the base side of the same run). - `check_conventions.py` passes. `pr_overlap.py` reports #9175, #9912, #10056, #10183, #10185, #10186, #10426, #10428, #10706 and #10718 on nearby lines of `Export.cpp`, the `guest_ces*` tests or the debt file; none changes these error paths (#10706 moves declarations into export headers). Merge order: this lands before #10718, which is rebased onto it (both change the Shift-JIS and EUC-JP decode paths in `Export.cpp` and the same `GuestCesJapanese.cpp` checks). ### 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: none; #10184 changes the EUC-JP scalar forms with the same rule <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-24 20:04:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:04:00Z.

Review: APPROVED


Reviewed the decoder error paths, wrapper output handling, test changes, and debt update. The new helpers distinguish invalid lead, bad/NUL trail, truncated sequence, and unassigned sequence lengths; the wrappers update only the outputs the measured behavior changes. The tests include console-captured sequences and preserve the separate EUC-JP output behavior called out in the debt entry. Hosted conventions/report checks pass; the PR also reports its focused macOS suite and a Linux guest_ces run on the same tree. I could not dispatch the manual full build from this account (GitHub returned HTTP 403). I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639752601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10722#pullrequestreview-5639752601). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:04:00Z. **Review:** APPROVED --- Reviewed the decoder error paths, wrapper output handling, test changes, and debt update. The new helpers distinguish invalid lead, bad/NUL trail, truncated sequence, and unassigned sequence lengths; the wrappers update only the outputs the measured behavior changes. The tests include console-captured sequences and preserve the separate EUC-JP output behavior called out in the debt entry. Hosted conventions/report checks pass; the PR also reports its focused macOS suite and a Linux guest_ces run on the same tree. I could not dispatch the manual full build from this account (GitHub returned HTTP 403). I found no blocking issue.
MarcZX10 commented 2026-10-24 20:20:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:20:31Z.

Review: APPROVED


Reviewed the full diff at 67e4ffb032f7e08c3b99138f6a5ec29c91fce8d1. The changes propagate measured failure lengths from the decoders and clear only the decoded character output while preserving argument-error behavior. The added MBCS cases cover truncation, bad lead/trail, embedded NUL, unassigned values and GB18030 four-byte lengths across all eight conversion forms; the PR also reports exhaustive console sweeps across 65,792 inputs/profile combinations and passing hosted Linux CES tests. Conventions, labels and eligibility passed. Product Linux/Windows and other focused workflow jobs were skipped under current repository policy; the submitted report separately records a macOS harness run and the Linux runner run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639803493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10722#pullrequestreview-5639803493). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:20:31Z. **Review:** APPROVED --- Reviewed the full diff at 67e4ffb032f7e08c3b99138f6a5ec29c91fce8d1. The changes propagate measured failure lengths from the decoders and clear only the decoded character output while preserving argument-error behavior. The added MBCS cases cover truncation, bad lead/trail, embedded NUL, unassigned values and GB18030 four-byte lengths across all eight conversion forms; the PR also reports exhaustive console sweeps across 65,792 inputs/profile combinations and passing hosted Linux CES tests. Conventions, labels and eligibility passed. Product Linux/Windows and other focused workflow jobs were skipped under current repository policy; the submitted report separately records a macOS harness run and the Linux runner run.
MarcZX10 commented 2026-10-25 02:54:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:54:52Z.

Review: APPROVED


Reviewed updated exact head 155abef132c3b7b9a4361d3160d7a39c183a031c. The rebase replaced the old local export declarations with the canonical CES headers while preserving the rejected-sequence length assertions. The current tests still cover invalid lead/trail, truncation, embedded NUL, and unassigned cases across the eight MBCS output forms; the author reports all 14 guest_ces* tests and conventions passing on this head. Hosted conventions, eligibility, labels and report pass; product build jobs are skipped. I did not independently rerun the CES suite on this head. No blocking issue remains in the reviewed integration.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641246900 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10722#pullrequestreview-5641246900). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T02:54:52Z. **Review:** APPROVED --- Reviewed updated exact head `155abef132c3b7b9a4361d3160d7a39c183a031c`. The rebase replaced the old local export declarations with the canonical CES headers while preserving the rejected-sequence length assertions. The current tests still cover invalid lead/trail, truncation, embedded NUL, and unassigned cases across the eight MBCS output forms; the author reports all 14 `guest_ces*` tests and conventions passing on this head. Hosted conventions, eligibility, labels and report pass; product build jobs are skipped. I did not independently rerun the CES suite on this head. No blocking issue remains in the reviewed integration.
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!10722
No description provided.