feat(libSceNKWebKit): implement WTF::StringImpl::utf8ForCharacters #14948
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14948"
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 w4rc0n on 2026-11-02T03:15:05Z.
What
WTF::StringImpl::utf8ForCharacterswas aNotImplementedstub in both overloads,(const LChar*, unsigned)and(const UChar*, unsigned, ConversionMode). Both now follow the pinned PS5 WebKit 11.xStringImpl.cppandtryGetUTF8ForCharacters, and returnExpected<CString, UTF8ConversionError>:INT32_MAX / 2(Latin-1) orINT32_MAX / 3(UTF-16) returnsOutOfMemorybefore any character is read, as in the source. As in the pinned allocator, a failed allocation still throws.SourceExhausted, and any other invalid sequence returnsIllegalSource(UTF8ConversionError.h).UTF8Conversion.cpp:66-75,StringImpl.cpp:1580-1585).StrictConversionReplacingUnpairedSurrogatesWithFFFDreplaces every unpaired surrogate.Both overloads reuse the UTF-8 conversion that
StringImpl::utf8already uses onmain. That conversion gains an optional error output, so its existing callers keep throwing as before. Its lenient path wrote every unpaired surrogate raw. This PR corrects it, soString::utf8,StringImpl::utf8andStringView::utf8onmain, and #14946'sStringprinting, now also replace unpaired surrogates with U+FFFD in lenient mode, except a lone final lead surrogate, as the pinned source does.Expected<CString, UTF8ConversionError>has the same layout as #14946'sExpected<String, …>:The debt layout entry records that this layout is unverified against console binaries.
tools/pr_overlap.pyon this head, withmainat0eba5db30d: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge withmain, GitHub's file lists show none of them changing these exports either. #13992, #14172 and #15241 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14947, in the same stack.Tested
Debian 12, GCC 12.2, Linux 6.18, Release, at the head
37f1179ceb27cd82586e020ed3ff3f3f77c4b0c7, which is on #14946's head59a53bbfcbd5eadd60fe1711a5157d57ca5bb3b2. No local changes.guest_nkwebkit_dates,guest_nkwebkit_numbers,nkwebkit_base,nkwebkit_config,nkwebkit_constants,nkwebkit_fastbitvector,nkwebkit_jsc,nkwebkit_palsessionid,nkwebkit_preferences,nkwebkit_resourceresponse,nkwebkit_webcoregeometry,nkwebkit_wtf,guest_nkwebkit_urlsandpublic_headerspass.nkwebkit_wtfcases cover:String::utf8,StringImpl::utf8andStringView::utf8exports in lenient mode, and one older test that expected the raw output, now corrected;tools/progress.py: both exports count as implemented (libSceNKWebKit 1348, against 1346 with #14946).tools/check_conventions.pypasses.libSceNKWebKit.sprx, read from disassembly only and not measured on a console.utf8ForCharacters(const LChar*, unsigned)(o5VwYgTgLtU) starts withcmp edx, 0x40000000, and theUCharoverload (NvD7vqlu22E) withcmp edx, 0x2aaaaaab. These are the sameMaxStringLength / 2and/ 3bounds as this PR. The surrogate handling was not compared with the module.a3b0234339d1e891d111f410cf9a3e7dd30d9ca6. It is AnyPS5'sBuildworkflow, dispatched in the author's fork withselect=true: the branch merged intomainat926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5, built onwindows-latestwith WinLibs GCC 15.2 (MinGW-w64, UCRT). None of the 672 selected tests failed; 6 AGC tests were skipped, whichcheck_skips.pyaccepts. That includes the nine NKWebKit tests,public_headersandpatched_libraries. The later rebases ontomain(now0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #14479, #13766, #14925 and #15911) changed onlydocs/dev/debt/libSceNKWebKit.md, sogit range-diffshows the code and tests under test are the same as at that run. A fork-internal pull request existed only to give the workflow a number.Not built or run: macOS. No title or homebrew was run.
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 BunnyFl on 2026-11-02T16:54:57Z.
Review: APPROVED
Cross-checked the length limits against firmware 13.42's own
libSceNKWebKit.sprx(system_ex/common_ex/lib, sha256e63acdc164592330a287cf6914c265336b27a357098a449c1609f8f82e104409), read from disassembly only, not measured on a console:utf8ForCharacters(const LChar*, unsigned)(o5VwYgTgLtU,0x1811e0) starts withcmp edx, 0x40000000.utf8ForCharacters(const UChar*, unsigned, ConversionMode)(NvD7vqlu22E,0x211f00) starts withcmp edx, 0x2aaaaaab.Those are exactly
length > MaxStringLength / 2andlength > MaxStringLength / 3inWtfString.cpp:1297and:1302, so the earlyOutOfMemorybounds match the shipped module, not just the pinned source.Build and test on Windows (WinLibs GCC,
BUILD_TESTING=ON), PR merged into currentmain:nkwebkit_wtfpasses. With the PR's source file taken frommain, the test executable doesn't link, since the exports are new, so there's nomaincontrol.I didn't compare the strict and lenient surrogate handling against the module. That part rests on the pinned
UTF8Conversion.cpp, and the tests cover it.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T03:18:04Z.
Review: APPROVED
@w4rc0n re-checked after the force-push.
37f1179cebis a rebase ofa3b0234339, the head I approved:git range-diffshows no change to any code or test line. The only differences are hunk context and the dropped edit of the "Additional callable exports" count line indocs/dev/debt/libSceNKWebKit.md, whichmainhas since reworded.On
37f1179cebmerged ontomain0540ef0ef2(Windows 11, WinLibs GCC 15.2.0, Release,nkwebkit_wtf_testsrebuilt),nkwebkit_wtfpassed, 1 of 1. Withmain'score/libs/prx/libSceNKWebKit/src/WtfString.cppput back,nkwebkit_wtf_testsdoesn't link. That says nothing about behaviour, and I added a mutation check this time. Mutation check, on the same merge: with the new unpaired-surrogate branch ofToUTF8always storing error 1 (instead of 2 for a trailing high surrogate),nkwebkit_wtffails in the new test's error-code check.check_conventions.pypasses.pr_overlap.py --branch: the rows with the same exports are your own #14946 (which this one builds on) and #14947 (also stacked on #14946). The other comparable rows share lines inExport.cpp, the export headers or the debt file but no exports; I haven't checked each of them against this PR. The tool couldn't compare about 50 more PRs, which conflict withmain.Approving again at
37f1179ceb.AI-assisted: yes (Claude Code)
Pull request closed