fix(libSceIcu): write utf8_appendCharSafeBody's isError only when the append fails #24088

Merged
GiannisG1 merged 1 commit from upstream-pr/24088 into main 2026-11-20 07:25:16 +00:00
GiannisG1 commented 2026-11-20 05:53:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GiannisG1 on 2026-11-20T05:53:19Z.


What

ICU's utf8_appendCharSafeBody dereferences pIsError only on its error path, when the code point does not fit, is a surrogate or is above U+10FFFF (ICU 68.2 utf_impl.cpp L215-L217; the same in the 78.1 submodule). Since #22164, the export checks isError with GuestWritable_nid_no_patch before every append. This has two effects:

  • A successful append with an isError pointer that ICU never touches is refused with std::invalid_argument.
  • Every call pays a host mapping lookup (HostMapping::Find on Linux, VirtualQuery on Windows). guest_icu_utf8 appends every code point from U+0080 to U+10FFFF with &error. It took 0.09-0.34 s here before #22164 and 1.9-4.7 s after, and it timed out at its 20 s limit in main's Linux job (run 44639208734, the guest_icu_utf8 (Timeout) entry).

This PR drops the up-front check. The error path already writes isError through GuestCopyOut_nid_no_patch, which refuses an unmapped or unwritable pointer, so a bad pointer is still refused where ICU would write through it. The debt entry #22164 added (still a pending fragment) now says that.

Tested

Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, head on main d50640e264.

  • guest_icu_utf8: the check that a successful append with an unwritable isError (0x10) throws is replaced by two checks. That append returns the new index, and the same pointer is refused when the append has no room. On main the first check fails (utf8_appendCharSafeBody_nid_postfix: invalid argument), 3 of 3 runs. With this PR the test passes 3 of 3, in 0.30-0.32 s against 1.9-2.5 s on main on this machine.
  • With #22460 (the other open Utf8.cpp change) merged on top, it merges cleanly and the test passes in 0.17-0.20 s.
  • Split suite (tools/suite.py: every test once, GPU tests on the GTX 1050 Ti, the HD 630 and llvmpipe) on this PR: GTX 1050 Ti, 6338 run, 0 failed (guest_icu_utf8 in 0.31 s). HD 630, 1457 GPU tests: the 9 failures of main 0626a8334f's own split suite on this machine, and agc_driver_frame_replay_rewind_copy, which is intermittent (#22028). llvmpipe, 1457: agc_driver_image_gather_lod, agc_driver_image_table_packed_guards, agc_driver_scattered_runs and agc_driver_sparse_dma_buf_straddle, the llvmpipe failures of the same main Linux job (the last from #23272, which this base still has). None is in libSceIcu.
  • check_conventions.py, check_test_registration.py, check_main_sync.py (merges cleanly with current main), check_compile.py, debt_fold.py --check and git diff --check are clean. tools/progress.py --module libSceIcu: nothing pending. pr_overlap.py --branch: no overlap with open pull requests.

No title speed is claimed.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5408540621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24088). Originally posted by [GiannisG1](https://github.com/GiannisG1) on 2026-11-20T05:53:19Z. --- ### What ICU's `utf8_appendCharSafeBody` dereferences `pIsError` only on its error path, when the code point does not fit, is a surrogate or is above U+10FFFF ([ICU 68.2 `utf_impl.cpp` L215-L217](https://github.com/unicode-org/icu/blob/release-68-2/icu4c/source/common/utf_impl.cpp#L215-L217); the same in the 78.1 submodule). Since #22164, the export checks `isError` with `GuestWritable_nid_no_patch` before every append. This has two effects: - A successful append with an `isError` pointer that ICU never touches is refused with `std::invalid_argument`. - Every call pays a host mapping lookup (`HostMapping::Find` on Linux, `VirtualQuery` on Windows). `guest_icu_utf8` appends every code point from U+0080 to U+10FFFF with `&error`. It took 0.09-0.34 s here before #22164 and 1.9-4.7 s after, and it timed out at its 20 s limit in `main`'s Linux job (run 44639208734, the `guest_icu_utf8 (Timeout)` entry). This PR drops the up-front check. The error path already writes `isError` through `GuestCopyOut_nid_no_patch`, which refuses an unmapped or unwritable pointer, so a bad pointer is still refused where ICU would write through it. The debt entry #22164 added (still a pending fragment) now says that. ### Tested Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, head on `main` `d50640e264`. - `guest_icu_utf8`: the check that a successful append with an unwritable `isError` (0x10) throws is replaced by two checks. That append returns the new index, and the same pointer is refused when the append has no room. On `main` the first check fails (`utf8_appendCharSafeBody_nid_postfix: invalid argument`), 3 of 3 runs. With this PR the test passes 3 of 3, in 0.30-0.32 s against 1.9-2.5 s on `main` on this machine. - With #22460 (the other open `Utf8.cpp` change) merged on top, it merges cleanly and the test passes in 0.17-0.20 s. - Split suite (`tools/suite.py`: every test once, GPU tests on the GTX 1050 Ti, the HD 630 and llvmpipe) on this PR: GTX 1050 Ti, 6338 run, 0 failed (`guest_icu_utf8` in 0.31 s). HD 630, 1457 GPU tests: the 9 failures of `main` `0626a8334f`'s own split suite on this machine, and `agc_driver_frame_replay_rewind_copy`, which is intermittent (#22028). llvmpipe, 1457: `agc_driver_image_gather_lod`, `agc_driver_image_table_packed_guards`, `agc_driver_scattered_runs` and `agc_driver_sparse_dma_buf_straddle`, the llvmpipe failures of the same `main` Linux job (the last from #23272, which this base still has). None is in libSceIcu. - `check_conventions.py`, `check_test_registration.py`, `check_main_sync.py` (merges cleanly with current `main`), `check_compile.py`, `debt_fold.py --check` and `git diff --check` are clean. `tools/progress.py --module libSceIcu`: nothing pending. `pr_overlap.py --branch`: no overlap with open pull requests. No title speed is claimed. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-20 05:56:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T05:56:14Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_utf8_tests built cleanly.
  • CTest (guest_icu_utf8):
    1/1 Test #3961: guest_icu_utf8 ...................   Passed    0.25 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/Utf8.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3961: guest_icu_utf8 ...................***Timeout  20.10 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that utf8_appendCharSafeBody in core/libs/prx/libSceIcu/Utf8.cpp only writes to isError on error via GuestCopyOut_nid_no_patch, matching upstream ICU 68.2 behavior in utf_impl.cpp where pIsError is only dereferenced when the code point cannot be appended.
    • Checked guest memory validation: GuestCopyOut_nid_no_patch properly validates guest address and returns false if unmapped/unwritable, triggering APS5_INVALID_ARG_EX on failure, preserving memory safety.
    • Verified error paths when isError is non-null vs null: when isError is non-null and scalar is invalid or buffer lacks capacity, GuestCopyOut_nid_no_patch writes 1 and returns index. When isError is null, ErrorValue fallback is written into text.
    • Verified core/libs/tests/GuestIcuUtf8.cpp updates: valid append with dummy pointer 0x10 returns index + width without dereferencing 0x10; failing append with 0x10 properly rejects and throws APS5_INVALID_ARG_EX.
    • Checked docs/dev/debt/changes/fix-libSceIcu-utf8-guest-pointers.md technical debt fragment accurately reflects the updated contract and conforms to debt documentation conventions.
    • Verified AGENTS.md compliance: no unauthorized comments added, no hardcoded title special cases, and all mechanical checks (conventions, formatting, test execution) passed.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988185287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24088#pullrequestreview-5988185287). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T05:56:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `06a05da18f`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_icu_utf8_tests` built cleanly. - **CTest** (`guest_icu_utf8`): ``` 1/1 Test #3961: guest_icu_utf8 ................... Passed 0.25 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/Utf8.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3961: guest_icu_utf8 ...................***Timeout 20.10 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified that utf8_appendCharSafeBody in core/libs/prx/libSceIcu/Utf8.cpp only writes to isError on error via GuestCopyOut_nid_no_patch, matching upstream ICU 68.2 behavior in utf_impl.cpp where pIsError is only dereferenced when the code point cannot be appended. - Checked guest memory validation: GuestCopyOut_nid_no_patch properly validates guest address and returns false if unmapped/unwritable, triggering APS5_INVALID_ARG_EX on failure, preserving memory safety. - Verified error paths when isError is non-null vs null: when isError is non-null and scalar is invalid or buffer lacks capacity, GuestCopyOut_nid_no_patch writes 1 and returns index. When isError is null, ErrorValue fallback is written into text. - Verified core/libs/tests/GuestIcuUtf8.cpp updates: valid append with dummy pointer 0x10 returns index + width without dereferencing 0x10; failing append with 0x10 properly rejects and throws APS5_INVALID_ARG_EX. - Checked docs/dev/debt/changes/fix-libSceIcu-utf8-guest-pointers.md technical debt fragment accurately reflects the updated contract and conforms to debt documentation conventions. - Verified AGENTS.md compliance: no unauthorized comments added, no hardcoded title special cases, and all mechanical checks (conventions, formatting, test execution) passed. Looks Good To Me
MarcZX10 commented 2026-11-20 06:03:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:03:03Z.

Review: APPROVED


Reviewed — looks good

The append now permits an unused isError pointer on success and validates it through the existing copy-out only when an error must be reported; I found no blocking defect in the changed code.

What I ran

Reviewed head 06a05da18f02a6740cb14103f254ff367516f18c using the prepared diff and reader repo_read.py. No commands or tests were run.

Results

Check Result Note
Changed code review passed Three changed files read
Tests and checks not run Author-reported results are not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or build checks were run. The PR description reports test and suite results, but those were not independently confirmed. All three files listed as reviewed in the manifest were read: core/libs/prx/libSceIcu/Utf8.cpp, core/libs/tests/GuestIcuUtf8.cpp, and docs/dev/debt/changes/fix-libSceIcu-utf8-guest-pointers.md. No files were listed as excluded in the manifest; a separate files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988237769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24088#pullrequestreview-5988237769). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T06:03:03Z. **Review:** APPROVED --- # Reviewed — looks good The append now permits an unused `isError` pointer on success and validates it through the existing copy-out only when an error must be reported; I found no blocking defect in the changed code. ## What I ran Reviewed head `06a05da18f02a6740cb14103f254ff367516f18c` using the prepared diff and reader `repo_read.py`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Three changed files read | | Tests and checks | not run | Author-reported results are not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or build checks were run. The PR description reports test and suite results, but those were not independently confirmed. All three files listed as reviewed in the manifest were read: `core/libs/prx/libSceIcu/Utf8.cpp`, `core/libs/tests/GuestIcuUtf8.cpp`, and `docs/dev/debt/changes/fix-libSceIcu-utf8-guest-pointers.md`. No files were listed as excluded in the manifest; a separate `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
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!24088
No description provided.