Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
GiannisG1:fix/icu-append-error-path-only
Nov 20, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
GiannisG1:fix/icu-append-error-path-only

Conversation

@GiannisG1

Copy link
Copy Markdown
Contributor

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 fix(libSceIcu): validate and safely copy isError pointer in utf8_appendCharSafeBody #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 fix(libSceIcu): copy lenient UTF-8 conversion and UTF-8 cursor guest pointers safely #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 (fix(agc): record CPU stores to pages that leave the write watch during a capture #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 perf(agc): bind chunk-crossing shared imports into the 64 MiB chunk imports #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

… append fails

ICU's utf8_appendCharSafeBody (utf_impl.cpp, the same in 68.2 and 78.1)
dereferences pIsError only on its error path. The up-front GuestWritable
check refused successful appends with a pointer ICU never touches and
added a host mapping lookup to every call; GuestCopyOut on the error
path already refuses an unwritable pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean
oneandonlydean merged commit 3a1b27b into boykopovar:main Nov 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants