feat(libSceIcu): copy the UTF-8 conversion operands through guest memory #25526
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25526"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pinewhite on 2026-11-22T07:23:51Z.
What
u_strFromUTF8,u_strFromUTF8WithSub,u_strToUTF8andu_strToUTF8WithSubnow convert between a source copied in from guest memory and an output buffer written once, instead of dereferencing the guest source directly and writing the destination unit by unit behind aGuestArena::HostWriteguard that threwNotImplemented_nid_no_patchwhen it could not open.GuestCopyInin page-sized chunks, stopping after the terminator for a-1length, asUtf32.cppandJavaUtf8.cppalready do. An unreadable source throwsstd::invalid_argumentinstead of faulting on the guest address.GuestCopyOut. The write guard over the destination, the destination length, the substitution count and the status is still opened before anything is read or written, so a refused write throws before any output changes.pDestLength,pNumSubstitutionsandpErrorCodegets the same final word as ICU.ustrtrns.cpp, which differs from the pinned ICU 78.1 copy only in pointer and type spellings for these functions. Malformed sequences consume the maximal subpart through the in-treeutf8_nextCharSafeBody_nid_postfix, implemented fromutf_impl.cppinUtf8.cpp.u_strFromUTF8Lenientis untouched because #22460 rewrites that function.python3 tools/progress.py --module libSceIcu: done 321 -> 325 of 2766 (11.61% -> 11.75%). The four exports no longer reachNotImplemented_nid_no_patch; nothing else moved.Tested
Host proof on Ubuntu 24.04 aarch64, g++ 13.3.0,
-std=c++20 -O1 -ffunction-sections -fdata-sections -Icore/libs, linked with-Wl,--gc-sections:core/libs/prx/libSceIcu/UtfConversions.cppandUtf8.cppcompiled by hand into a runner. Shimmed seams:GuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patch(memcpy over host memory plus a registry of inaccessible ranges),GuestArenaBeginHostWrite_nid_postfix,GuestArenaEndHostWrite_nid_postfixandNotImplementedAt_nid_no_patch.core/libs/tests/GuestIcuUtfConversions.cppwith the new cases: exit 0 against the new object, exit 0 against the pre-change object.u_strFromUTF8WithSub_74,u_strToUTF8WithSub_74): 20,000 randomized decode and encode cases with capacities 0-14, lengths 0-12,-1and counted sources, and substitutions-1, U+FFFD, NUL and U+1F642, plus 200 aliased-scalar layouts; return, length, status, substitution count and every output byte agree.std::invalid_argument, exit 0.Not run: the CMake/ctest guest suites (no PS5 toolchain, ICU 78.1 build or emulator run in this environment), the Windows write-watch path this guard also serves, and any console comparison.
Note: PR #22460 rewrites
u_strFromUTF8Lenientin the same file and edits the same test file. The lenient body here is byte-for-byte unchanged, so the overlap is adjacent hunks plus the test insertion point and needs a rebase whichever merges second.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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T07:26:12Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a9e370a789:tools/check_conventions.pypassed.guest_icu_utf_conversions_testsbuilt cleanly.guest_icu_utf_conversions):core/libs/prx/libSceIcu/UtfConversions.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:41:21Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the inspected code; the host experiments and differential results below are author-reported, and console behavior remains unverified.
What I ran
Reviewed head
a9e370a789c26ef061d9323c289a3d84b5a2fb0cusing the prepared diff and the pinnedrepo_read.pyreader. No tests or build commands were run.Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/libs/prx/libSceIcu/UtfConversions.cpp(reader output was truncated after line 100),core/libs/tests/GuestIcuUtfConversions.cpp(reader output was truncated after line 100), anddocs/dev/debt/changes/feat-icu-string-utf8-conversions.md. All three changed files are listed as reviewed in the manifest; the changed source and test files were not fully read, so this review is incomplete.Results
Findings
Blocking
None identified in the portions inspected.
Non-blocking
None.
Not verified
The full changed source and test files were not read; reader output stopped at line 100. The CMake/ctest guest suites, Windows write-watch path, and console comparison were not run, as also stated in the PR description. The author's reported host proof and ICU differential were not independently verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by throny on 2026-11-22T16:57:00Z.
Review: COMMENTED
Review: ⚠️ the conversions match ICU 78.1, but the new tests also pass on
mainBasis: code read against
3rdparty/icu049e0d6a42(ustrtrns.cpp) · heada9e370a789Checked
UtfConversions.cpp:195,:245), and an incoming warning carries on. Argument validation,pDestLengthon overflow,U_STRING_NOT_TERMINATED_WARNING/U_BUFFER_OVERFLOW_ERRORand the invalid-character partial output all follow ICU's slow paths. The existingGuestIcuUtfMemoryalias matrix still holds.output.size()(never more than the capacity), plus a terminator only when it fits. The copy-in for -1 stops at the page that holds the NUL. No files overlap with #25528 or #25502.Findings
guest_icu_utf_conversionsPassed withUtfConversions.cppreverted, and the PR body says the same ("exit 0 against the pre-change object"). Nothing pins the change, which is that an unreadable source throws instead of faulting. Please add aGuestIcuUtfMemorycase with:PROT_NONEpage, expecting a throw:204-205and:254-255: the substitution count is zeroed beforeReadSource. An unreadable source therefore throws after an output has already changed, and when the count aliasesstatusan incoming -124 is cleared. ICU stores in the same order, so the code is fine, but the fragment's claim that it throws "before any output changes" is not accurate.Suggested action: add the test (1) and fix the fragment wording (2); then merge
AI-assisted review (Claude Code) · head
a9e370a789· basemain23b8772462