fix(libSceNKWebKit): copy WTF string value guest pointers safely #22470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22470"
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-17T17:28:57Z.
What
WtfValues.cppin libSceNKWebKit read and wrote guest objects directly in the string value exports. They now copy guest memory in, compute on host copies and copy results out, following the pattern of the mergedWTF::MediaTimeandWebCore::Regionfixes in this library (GuestCopyIn_nid_no_patch,GuestCopyOut_nid_no_patch, failure throughNotImplementedAt_nid_no_patch).StringImpl::replace(char16_t, const LChar*, unsigned): the guest replacement bytes are checked readable in 4 KiB chunks before the result string is allocated. An oversizedrepStrLengthwith a short guest buffer now fails before any allocation, where it used to allocate up to 2 GiB and then read past the buffer. The bytes are read once into the first match position of the result, and later matches copy from there. 8-bit and 16-bit results are byte-identical to before.StringView::SplitResult::Iterator::findNextSubstringandoperator++: the iterator and itsSplitResultare copied in. Onlyposition,lengthandisDoneare written back, so the iterator padding stays as before. The scan moved into a host helper.String::split,splitAllowingEmptyEntries,charactersWithNullTermination,toFloat,toDouble,isolatedCopy() const &andisolatedCopy() &&: theStringImpl*of the guestStringis copied in.toFloatandtoDoubleparse into a hostokflag and copy it out once, so a non-nullokgets the same byte as before.isolatedCopy() &&clears the guestStringthroughGuestCopyOut_nid_no_patchbefore it hands over the reference, so a read-onlyStringkeeps its reference and refcount.An unreadable or unwritable guest pointer now fails through
NotImplementedAt_nid_no_patchinstead of faulting. Nullthisand null replacement still throwstd::invalid_argumentas before.I split the file into two PRs by topic.
WTF::Persistence::Encoder/DecoderandWTF::URLfrom the same file are in a separate PR (fix/nkwebkit-wtf-persistence-url-guest-pointers).False positives left unchanged (still listed by
tools/guest_pointer_audit.py libSceNKWebKit):StringImpl::replace(char16_t, char16_t)andStringImpl::replace(char16_t, const LChar*, unsigned), parameterself:StringImplobjects are allocated by the library (StringImpl::create,createUninitialized). They are host objects, likeRegion::Shapein the mergedRegionfix.SplitResult::Iterator::operator++,self (dereference): this is thereturn *self;of the reference return, and nothing is read. The mergedMediaTime::operator=keeps the same hit.Characters behind a
StringView(theSplitResultview) are read the same way as in every otherStringViewexport of this library, and I did not change that here.No debt change: no debt entry describes the old behaviour.
Tested
Arch Linux, GCC, Release (
-DBUILD_TESTING=ON).nkwebkit_wtfstringvaluesguestpointers(tests/WtfStringValuesGuestPointers.cpp, under 0.1 s):this(0x10) and with an unwritableok;SplitResultpointer that cannot be read, and a read-only iterator page (left unchanged);Stringpassed toisolatedCopy() &&(keeps its impl and refcount);PROT_NONEpage, and an oversized count (0x10000000) over a 3-byte buffer;ctest --test-dir build -R 'public_headers|nkwebkit' -j 4: 187/187 passed (includes the existingnkwebkit_wtfvaluesbehaviour tests).LoadStringImplreadingstring->impldirectly: segfault;CopyGuestLatin1usingmemcpyinstead ofGuestCopyIn_nid_no_patch: segfault;*self = iteratordirectly: segfault.python3 tools/progress.py --root . --module libSceNKWebKit: 3308 done on bothorigin/mainand this branch.python3 tools/check_conventions.py --base origin/main: all checks passed.Overlap
python3 tools/pr_overlap.py --namesfor all 33WtfValues.cppexports listed by the audit: all implemented onmainin libSceNKWebKit, no open PR edits them.python3 tools/pr_overlap.py --branch fix/nkwebkit-wtf-string-values-guest-pointers: no overlap with open pull requests.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-17T17:33:50Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
8e2f06fa5f:tools/check_conventions.pypassed.nkwebkit_wtfstringvaluesguestpointers_testsbuilt cleanly.nkwebkit_wtfstringvaluesguestpointers):core/libs/prx/libSceNKWebKit/src/WtfValues.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-23T07:05:01Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code supports merging.
What I ran
Reviewed head
8e2f06fa5f8cb54042bfe1f4fa781d709727ebb4. No commands or tests were run; the author-reported test results were not independently verified. Readdescription.md,commits.md,manifest.json,diff.patch, and the complete text of both changed files. Also inspected targeted guest-copy, string helper, and CMake test-discovery code. Both changed files were included in the review folder; no changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported test, mutation-check, progress, and convention-check results were not independently run. Console behavior and other operating systems were not verified.
To get this to a good state
Nothing is required.