Repository navigation
fix(libSceIcu): write utf8_appendCharSafeBody's isError only when the append fails - #24088
Conversation
… 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
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 06a05da18f:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_icu_utf8_testsbuilt 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.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #3961: guest_icu_utf8 ...................***Timeout 20.10 sec 0% tests passed, 1 tests failed out of 1 - 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
left a comment
There was a problem hiding this comment.
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.
What
ICU's
utf8_appendCharSafeBodydereferencespIsErroronly on its error path, when the code point does not fit, is a surrogate or is above U+10FFFF (ICU 68.2utf_impl.cppL215-L217; the same in the 78.1 submodule). Since #22164, the export checksisErrorwithGuestWritable_nid_no_patchbefore every append. This has two effects:isErrorpointer that ICU never touches is refused withstd::invalid_argument.HostMapping::Findon Linux,VirtualQueryon Windows).guest_icu_utf8appends 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 inmain's Linux job (run 44639208734, theguest_icu_utf8 (Timeout)entry).This PR drops the up-front check. The error path already writes
isErrorthroughGuestCopyOut_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
maind50640e264.guest_icu_utf8: the check that a successful append with an unwritableisError(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. Onmainthe 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 onmainon this machine.Utf8.cppchange) merged on top, it merges cleanly and the test passes in 0.17-0.20 s.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_utf8in 0.31 s). HD 630, 1457 GPU tests: the 9 failures ofmain0626a8334f's own split suite on this machine, andagc_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_runsandagc_driver_sparse_dma_buf_straddle, the llvmpipe failures of the samemainLinux 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 currentmain),check_compile.py,debt_fold.py --checkandgit diff --checkare clean.tools/progress.py --module libSceIcu: nothing pending.pr_overlap.py --branch: no overlap with open pull requests.No title speed is claimed.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code