feat(libSceIcu): decode default-encoded copies as UTF-16 #26469

Merged
ynkmyz233 merged 1 commit from upstream-pr/26469 into main 2026-11-24 23:02:47 +00:00
ynkmyz233 commented 2026-11-24 00:41:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ynkmyz233 on 2026-11-24T00:41:54Z.


What

Complete u_uastrcpy and u_uastrncpy by decoding byte strings into UTF-16 with ICU's current default converter. The bounded copy uses the count for both source bytes and destination UTF-16 units. Both exports copy through checked guest memory and release the converter through the existing cache. Bundled ICU reference

The branch check reports overlapping edits in Invariant.cpp with #22132 and in the technical debt entry with #25957. #22132 checks guest pointers in other invariant copy routines. #25957 covers conversion in the opposite direction. Both conversion directions can run independently. The manually reviewed branch diffs for #13589, #14144, #14340, and #14443 contain the older ASCII-only copies.

Tested

Windows 10 x64 (19045), MinGW-w64 GCC 15.2.0, Release. Passed guest_icu_version, guest_icu_converter_helpers, and guest_icu_data_memory. The version test compares the guest exports against both bundled ICU routines, including malformed and truncated UTF-8, exact capacity, a supplementary character at an internal chunk boundary, and an ISO-8859-1 default.

Passed tools/check_conventions.py, 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:5463859067 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26469). Originally posted by [ynkmyz233](https://github.com/ynkmyz233) on 2026-11-24T00:41:54Z. --- ### What Complete `u_uastrcpy` and `u_uastrncpy` by decoding byte strings into UTF-16 with ICU's current default converter. The bounded copy uses the count for both source bytes and destination UTF-16 units. Both exports copy through checked guest memory and release the converter through the existing cache. [Bundled ICU reference](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/ustr_cnv.cpp) The branch check reports overlapping edits in `Invariant.cpp` with #22132 and in the technical debt entry with #25957. #22132 checks guest pointers in other invariant copy routines. #25957 covers conversion in the opposite direction. Both conversion directions can run independently. The manually reviewed branch diffs for #13589, #14144, #14340, and #14443 contain the older ASCII-only copies. ### 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_version`, `guest_icu_converter_helpers`, and `guest_icu_data_memory`. The version test compares the guest exports against both bundled ICU routines, including malformed and truncated UTF-8, exact capacity, a supplementary character at an internal chunk boundary, and an ISO-8859-1 default. Passed `tools/check_conventions.py`, `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-24 00:44:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-24T00:44:45Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_version_tests built cleanly.
  • CTest (guest_icu_version):
    1/1 Test #4128: guest_icu_version ................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/Invariant.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4128: guest_icu_version ................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 Invariant.cpp ReadEncodedText and CopyDecodedText handling of guest memory and chunking boundaries without integer overflow
    • Verified DecodeDefault converter acquisition and release lifecycle with u_releaseDefaultConverter_nid_postfix
    • Verified u_uastrcpy_nid_postfix and u_uastrncpy_nid_postfix behavior on null pointers, negative count, and zero count matching library conventions
    • Verified u_uastrncpy length bounds semantics where length bounds both input bytes and destination char16_t units and single null termination behavior
    • Verified docs/dev/debt/changes fragments adherence to repository technical debt conventions and AGENTS.md rules

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6031880692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26469#pullrequestreview-6031880692). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-24T00:44:45Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `cdd937c4aa`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_icu_version_tests` built cleanly. - **CTest** (`guest_icu_version`): ``` 1/1 Test #4128: guest_icu_version ................ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/Invariant.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4128: guest_icu_version ................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 Invariant.cpp ReadEncodedText and CopyDecodedText handling of guest memory and chunking boundaries without integer overflow - Verified DecodeDefault converter acquisition and release lifecycle with u_releaseDefaultConverter_nid_postfix - Verified u_uastrcpy_nid_postfix and u_uastrncpy_nid_postfix behavior on null pointers, negative count, and zero count matching library conventions - Verified u_uastrncpy length bounds semantics where length bounds both input bytes and destination char16_t units and single null termination behavior - Verified docs/dev/debt/changes fragments adherence to repository technical debt conventions and AGENTS.md rules Looks Good To Me
catminou4 commented 2026-11-24 09:30:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-24T09:30:31Z.

Review: COMMENTED


Built libSceIcu and ran guest_icu_version_tests on Linux (x86-64, GCC 11): passes.

Control — reverted Invariant.cpp to origin/main, kept the new DefaultEncodingDecode test: the test aborts with "u_uastrcpy_nid_postfix not implemented". On main these exports are stubs; this PR implements them.

u_uastrcpy/u_uastrncpy now decode the default encoding to UTF-16 through the bundled ICU converter, following ICU 78.1 ustr_cnv.cpp. The test is a genuine differential check against the bundled ICU's own u_uastrcpy/u_uastrncpy: it covers empty input, ASCII, 2-byte and 4-byte UTF-8, a truncated multi-byte sequence, invalid bytes, and — for every input — every bounded count 0..10, asserting identical output and termination. It also checks the exact-fit no-terminator case and a 2047-char boundary.

The debt fragment is precise about the semantics (positive count bounds both input bytes and output units, NUL written only when there is room, unbounded rejects input beyond ICU's signed length) and honest that the console's default encoding and non-ASCII behavior are unverified. Clean, mergeable feat.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6036719444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26469#pullrequestreview-6036719444). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T09:30:31Z. **Review:** COMMENTED --- Built `libSceIcu` and ran `guest_icu_version_tests` on Linux (x86-64, GCC 11): passes. Control — reverted `Invariant.cpp` to `origin/main`, kept the new `DefaultEncodingDecode` test: the test aborts with "u_uastrcpy_nid_postfix not implemented". On `main` these exports are stubs; this PR implements them. `u_uastrcpy`/`u_uastrncpy` now decode the default encoding to UTF-16 through the bundled ICU converter, following ICU 78.1 `ustr_cnv.cpp`. The test is a genuine differential check against the bundled ICU's own `u_uastrcpy`/`u_uastrncpy`: it covers empty input, ASCII, 2-byte and 4-byte UTF-8, a truncated multi-byte sequence, invalid bytes, and — for every input — every bounded count 0..10, asserting identical output and termination. It also checks the exact-fit no-terminator case and a 2047-char boundary. The debt fragment is precise about the semantics (positive count bounds both input bytes and output units, NUL written only when there is room, unbounded rejects input beyond ICU's signed length) and honest that the console's default encoding and non-ASCII behavior are unverified. Clean, mergeable feat.
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!26469
No description provided.