fix(libSceIcu): copy invariant conversion guest pointers safely #22132
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22132"
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 domx4q on 2026-11-17T06:19:04Z.
What
u_charsToUChars,u_UCharsToChars,u_austrcpyandu_austrncpyinlibSceIcu/Invariant.cppno longer dereference guest pointers directly.u_charsToUCharsandu_UCharsToCharsfirst check that the whole destination is writable withGuestWritable_nid_no_patch. They then convert in 4096-element chunks: copy the source in withGuestCopyIn_nid_no_patch, convert the host copy, and copy the result out withGuestCopyOut_nid_no_patch. Memory use stays bounded for any length.u_austrcpyandu_austrncpyread the UTF-16 source in page-bounded chunks: each copy runs to the end of the current 4096-byte page or to the bound, the same wayCopyGuestString_nid_no_patchreads guest strings, and the next page is read only if no terminator was found. A unit that straddles a page boundary is copied on its own. They stop at the same terminator or bound as before. They still throwNotImplemented_nid_no_patchon a unit above0x7fbefore writing anything. They then write the narrowed bytes, plus the terminator where one was written before, with one checked copy.NotImplemented_nid_no_patchand keepserrno, which is howConverterHelpers.cpphandles it; this library has no documented error code for these helpers. An unwritable destination is left unchanged.guest_icu_versiontests cover them and pass as before.The new guest-pointer test lives in a separate
GuestIcuInvariant.cpp. The existing invariant tests are inGuestIcuVersion.cpp, which a parallelVersion.cppchange may touch.guest_pointer_audit.py libSceIcuno longer lists anything inInvariant.cpp. The debt entries for these helpers describe null-pointer and console behaviour, not the direct dereference, so there is no fragment.Overlap
pr_overlap.py --names u_UCharsToChars u_austrcpy u_austrncpy u_charsToUChars: all present on main, no open PR adds them or edits their bodies.pr_overlap.py --branch fix/icu-invariant-guest-pointers: reported #19985 (feat(libSceIcu): implement uprv_sortArray) as unconfirmed, because both PRs editcore/libs/prx/libSceIcu/CMakeLists.txt. I compared the two by hand. #19985 adds sources and its array test blocks in other places in that file (sources list and afterguest_icu_list). This PR adds a separate block afterguest_icu_comparisons. The two do not touch the same lines or functions.Tested
Arch Linux, GCC, Release (
-DBUILD_TESTING=ON).ctest -R 'guest_icu_invariant|guest_icu_version$|guest_icu_version_extents|^public_headers$': all pass.guest_icu_invariant. It maps two read-write pages, onePROT_NONEguard page and one read-only page (Windows:PAGE_NOACCESS/PAGE_READONLY), then checks:0x10) source or destination, a read-only destination, or a source or destination running into the guard page, throwsstd::runtime_error, keepserrno, and leaves destinations unchanged.mainversion ofInvariant.cppmakes the test SEGFAULT.u_austrcpymakes the test abort at "destinations running into the guard page stay unchanged".u_charsToUCharsregardless of the remaining length makes it abort.check_conventions.py --base origin/main: passes.debt_fold.py --checkreportsdocs-nkwebkit-drop-readded-count-lines.md, which fails the same way onmain.guest_icu_invariant,guest_icu_versionandguest_icu_version_extentseach take 0.00 s on this branch;guest_icu_invariantis new, so there is nomainfigure for it. Every guest read copies a page-bounded chunk or a known length, never a single element unless that element straddles a page.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-17T06:23:46Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a76636b2c7:tools/check_conventions.pypassed.guest_icu_invariant_testsbuilt cleanly.guest_icu_invariant):core/libs/prx/libSceIcu/Invariant.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-17T06:38:51Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. Head
a76636b2c77fe5cea5d0f74a9a21e0b5636cbaa0, basemain.What I ran
a76636b2c77fe5cea5d0f74a9a21e0b5636cbaa0diff.patch,manifest.json,files.jsonanddescription.md.python3 repo_read.py search NotImplementedAt_nid_no_patch corepython3 repo_read.py search GuestWritable_nid_no_patch corepython3 repo_read.py search configure_windows_unwind core/libs/prx/libSceIcu/CMakeLists.txtpython3 repo_read.py cat core/libs/prx/libc/src/General.cpp 1155 1175python3 repo_read.py cat core/libs/prx/libc/src/General.cpp 836 860Results
General.hppdeclares every helper the new code callsstd::runtime_errorGeneral.cpp1159–1162configure_windows_unwindblocksFindings
Blocking
None verified.
Non-blocking
diff.patch:112). In the narrowing loop the same holds (diff.patch:130). If a source fails on a later chunk, the earlier chunks are already in the destination. The description says destinations are unchanged on failure. The tests check that only for single-chunk inputs (core/libs/tests/GuestIcuInvariant.cpp, thechars[0] == 'X'check and theguard - 4check). Either state the limit in the description or check the source chunk before writing (diff.patch:108,diff.patch:126).u_charsToUCharsandu_UCharsToCharseach place 4 KiB and 8 KiB buffers on the stack (diff.patch:106-107,diff.patch:124-125). I did not check the guest thread stack size, so this is a question, not a defect.u_austrcpy.ReadUnitsreads the whole source into a heapstd::u16stringbefore writing (diff.patch:142). Memory now scales with the source length, which the old loop did not. This is bounded by the source, so it is a cost, not a bug.Not verified
guest_pointer_audit.pyandcheck_conventions.pywere not run. I did not check the claim thatInvariant.cppno longer appears in the audit.GuestWritable_nid_no_patchon Linux goes throughHostMapping::Find(General.cpp851). I did not confirm that it sees the test'smmappages, so the read-only and guard-page tests depend on that.VirtualAlloc,VirtualProtectandVirtualFreepaths in the test were not built or checked.CMakeLists.txtandInvariant.cppwere read through the diff hunks, not in full at head. The new test file was read through the diff.To get this to a good state
Nothing is required. Optional:
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T23:05:11Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at
3831951f376193d31fa5919f0773684c1e0628adreplaces direct guest-pointer access in the four invariant conversion helpers with checked copies and adds focused guard-page tests; no concrete defect was found in the changed code.What I ran
Read the prepared description, commits, manifest, diff, and all three changed files at the pinned head. No commands or tests were run in this review.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and test results, including the reported Linux and Windows behavior, were not independently verified. No other repository files were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:25:46Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code supports merging, and the author-reported tests cover the new pointer handling.
What I ran
Reviewed head
b75fb308c052fcb30260d8efcc99a9b931543e37. No commands or tests were run in this review; the test results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and test results were not independently verified. The report states the targeted CTest cases, convention check, and mutation checks passed on Arch Linux with GCC Release. Console behavior and Windows execution were not verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:23:56Z.
Review: COMMENTED
Built the submitted invariant conversion implementation and ran
GuestIcuInvarianton Linux. It passed the read-only and unmapped destination cases, chunked widening and narrowing, and the sentinel checks.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.