feat(libSceIcu): encode UTF-16 copies with the default converter #25957

Open
ynkmyz233 wants to merge 1 commit from upstream-pr/25957 into main
ynkmyz233 commented 2026-11-23 00:58:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ynkmyz233 on 2026-11-23T00:58:27Z.


What

Complete Unicode-to-default-encoding support in u_austrcpy and u_austrncpy. Both now encode UTF-16 using the bundled ICU default converter, under the same lock that protects changes to the default encoding. The bounded function limits both the number of source code units read and the number of output bytes written. It writes one terminator when space permits.

#22132 touches the former implementations in Invariant.cpp to check guest pointers and keeps their ASCII input limit. This PR moves those two exports next to the default converter and adds the missing encoding behavior.

Tested

Windows 10 x64 (19045), MinGW-w64 GCC 15.2.0, Release. Passed guest_icu_converter_helpers, guest_icu_version, and guest_icu_converter_file_separator. Tested UTF-8 output for accented and supplementary characters, encoded bytes truncated within a character, exact capacity, a bounded input without a terminator, more than one conversion chunk, and switching the default to ISO-8859-1. The existing ASCII copy coverage also ran.

Passed tools/check_conventions.py --base origin/main, tools/debt_fold.py --check, and the public-header audit. Console behavior remains unverified.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5445287815 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25957). Originally posted by [ynkmyz233](https://github.com/ynkmyz233) on 2026-11-23T00:58:27Z. --- ### What Complete Unicode-to-default-encoding support in `u_austrcpy` and `u_austrncpy`. Both now encode UTF-16 using the bundled [ICU default converter](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/ustr_cnv.cpp), under the same lock that protects changes to the default encoding. The bounded function limits both the number of source code units read and the number of output bytes written. It writes one terminator when space permits. #22132 touches the former implementations in `Invariant.cpp` to check guest pointers and keeps their ASCII input limit. This PR moves those two exports next to the default converter and adds the missing encoding behavior. ### 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 10 x64 (19045), MinGW-w64 GCC 15.2.0, Release. Passed `guest_icu_converter_helpers`, `guest_icu_version`, and `guest_icu_converter_file_separator`. Tested UTF-8 output for accented and supplementary characters, encoded bytes truncated within a character, exact capacity, a bounded input without a terminator, more than one conversion chunk, and switching the default to ISO-8859-1. The existing ASCII copy coverage also ran. Passed `tools/check_conventions.py --base origin/main`, `tools/debt_fold.py --check`, and the public-header audit. Console behavior remains unverified. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-23 00:59:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T00:59:34Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against f06aa4009a:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_converter_helpers_tests built cleanly.
  • CTest (guest_icu_converter_helpers):
    1/1 Test #4140: guest_icu_converter_helpers ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/ConverterHelpers.cpp, core/libs/prx/libSceIcu/Invariant.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4140: guest_icu_converter_helpers ......Subprocess aborted***Exception:   0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified CopyConverterInput page-boundary chunking, 64-bit address overflow check, and null terminator scan in core/libs/prx/libSceIcu/ConverterHelpers.cpp
    • Verified DefaultConverterMutex synchronization and RAII release via u_releaseDefaultConverter within EncodeDefault
    • Verified u_austrcpy and u_austrncpy parameter checks (null checks, count < 0, count == 0) and CopyOut integration in core/libs/prx/libSceIcu/ConverterHelpers.cpp
    • Verified ICU ucnv_fromUnicode buffer streaming loop logic and trailing null termination handling for both bounded and unbounded paths
    • Verified AGENTS.md compliance regarding comments, debt fragment formatting (docs/dev/debt/changes/feat-libsceicu-default-encoding-copies.md), and conventional commits

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015501172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25957#pullrequestreview-6015501172). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-23T00:59:34Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `f06aa4009a`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_icu_converter_helpers_tests` built cleanly. - **CTest** (`guest_icu_converter_helpers`): ``` 1/1 Test #4140: guest_icu_converter_helpers ...... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/ConverterHelpers.cpp`, `core/libs/prx/libSceIcu/Invariant.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4140: guest_icu_converter_helpers ......Subprocess aborted***Exception: 0.12 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified CopyConverterInput page-boundary chunking, 64-bit address overflow check, and null terminator scan in core/libs/prx/libSceIcu/ConverterHelpers.cpp - Verified DefaultConverterMutex synchronization and RAII release via u_releaseDefaultConverter within EncodeDefault - Verified u_austrcpy and u_austrncpy parameter checks (null checks, count < 0, count == 0) and CopyOut integration in core/libs/prx/libSceIcu/ConverterHelpers.cpp - Verified ICU ucnv_fromUnicode buffer streaming loop logic and trailing null termination handling for both bounded and unbounded paths - Verified AGENTS.md compliance regarding comments, debt fragment formatting (docs/dev/debt/changes/feat-libsceicu-default-encoding-copies.md), and conventional commits Looks Good To Me
MarcZX10 commented 2026-11-23 01:25:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:25:59Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: bounded copies currently choose a byte capacity from the UTF-16 unit count, which can prevent termination when the encoding expands characters.

What I ran

  • Reviewed head f06aa4009a50c7da9c53d71d35431384fd5241a5 against base main; no merged-preview check was run.
  • Read the prepared description, commit list, manifest, diff, and full text of every changed file listed in the manifest through repo_read.py.
  • No commands or tests were run in this review; the test results in the PR description are author-reported.

Results

Check Result Note
Diff and changed files passed All five changed files read
Tests not run Author-reported tests were not rerun
Console behavior not run Unverified by author

Findings

Blocking

  • core/libs/prx/libSceIcu/ConverterHelpers.cpp:230: u_austrncpy passes the UTF-16 unit count as the output byte capacity. With a positive count of 1 and a source containing one character that encodes to multiple bytes (for example, é under UTF-8), ICU writes only the first encoded byte and returns overflow; because no output space remains, the function emits no terminator. The documented bounded behavior requires a terminator when space permits, but more generally this does not match ICU's bounded copy semantics: the count bounds input units while converted output may exceed that capacity, and the API has no destination-size parameter. Confirm the intended semantics and implement the bounded conversion accordingly; add a case that checks the required output and termination behavior for an expanding encoding.

Non-blocking

None.

Sources

Not verified

  • Tests, conventions checks, debt-fold checks, public-header audit, console behavior, and behavior on other host/toolchain configurations were not run by this review.
  • files.json was not available in the prepared review folder; the manifest lists five changed files, all of which were read. No excluded-file list could be confirmed.

To get this to a good state

  • Resolve the bounded-copy semantics for expanding encodings and add coverage for the required output and termination behavior. Rerun the converter helper tests and relevant repository checks on the updated head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015617118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25957#pullrequestreview-6015617118). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T01:25:59Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: bounded copies currently choose a byte capacity from the UTF-16 unit count, which can prevent termination when the encoding expands characters. ## What I ran - Reviewed head `f06aa4009a50c7da9c53d71d35431384fd5241a5` against base `main`; no merged-preview check was run. - Read the prepared description, commit list, manifest, diff, and full text of every changed file listed in the manifest through `repo_read.py`. - No commands or tests were run in this review; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All five changed files read | | Tests | not run | Author-reported tests were not rerun | | Console behavior | not run | Unverified by author | ## Findings ### Blocking - `core/libs/prx/libSceIcu/ConverterHelpers.cpp:230`: `u_austrncpy` passes the UTF-16 unit count as the output byte capacity. With a positive count of 1 and a source containing one character that encodes to multiple bytes (for example, `é` under UTF-8), ICU writes only the first encoded byte and returns overflow; because no output space remains, the function emits no terminator. The documented bounded behavior requires a terminator when space permits, but more generally this does not match ICU's bounded copy semantics: the count bounds input units while converted output may exceed that capacity, and the API has no destination-size parameter. Confirm the intended semantics and implement the bounded conversion accordingly; add a case that checks the required output and termination behavior for an expanding encoding. ### Non-blocking None. ## Sources - [ConverterHelpers.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/f06aa4009a50c7da9c53d71d35431384fd5241a5/core/libs/prx/libSceIcu/ConverterHelpers.cpp#L221-L231) - [PR description](https://github.com/boykopovar/AnyPS5/pull/25957) ## Not verified - Tests, conventions checks, debt-fold checks, public-header audit, console behavior, and behavior on other host/toolchain configurations were not run by this review. - `files.json` was not available in the prepared review folder; the manifest lists five changed files, all of which were read. No excluded-file list could be confirmed. ## To get this to a good state - Resolve the bounded-copy semantics for expanding encodings and add coverage for the required output and termination behavior. Rerun the converter helper tests and relevant repository checks on the updated head.
ligmaSec commented 2026-12-03 10:38:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:38:21Z.

Review: COMMENTED


The GuestIcuConverterHelpers fixture coverage passed on Linux with the exact implementation from this head. The fixture covers bounded input, chunked output, termination and the selected default encoding.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168113515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25957#pullrequestreview-6168113515). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T10:38:21Z. **Review:** COMMENTED --- The GuestIcuConverterHelpers fixture coverage passed on Linux with the exact implementation from this head. The fixture covers bounded input, chunked output, termination and the selected default encoding. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/25957:upstream-pr/25957'
git switch 'upstream-pr/25957'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/25957'
git switch 'upstream-pr/25957'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/25957'
git switch 'upstream-pr/25957'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/25957'
git switch 'main'
git merge --squash 'upstream-pr/25957'
git switch 'main'
git merge --ff-only 'upstream-pr/25957'
git switch 'main'
git merge 'upstream-pr/25957'
git push origin 'main'
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!25957
No description provided.