feat(libSceJsc): implement WTF UTF-8 conversion and JSON value accessors #18442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18442"
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 SHOnnay on 2026-11-11T14:26:09Z.
What
Implements 17 libSceJsc exports that threw.
UTF-8 (11):
WTF::Unicode::convertLatin1ToUTF8WTF::Unicode::convertUTF16ToUTF8(const UChar**, const UChar*, char**, char*, bool)WTF::Unicode::convertUTF8ToUTF16WTF::Unicode::convertUTF8ToUTF16ReplacingInvalidSequencesStringImpl::utf8Impl,StringImpl::tryGetUtf8,StringImpl::tryGetUtf8ForRangeStringView::tryGetUtf8String::tryGetUtf8overloadsString::utf8()JSON (6):
JSONImpl::Value::asValue,asBoolean,asStringJSONImpl::ArrayBase::length,endand the D2 destructorDepends on #18430, which depends on #18420. This branch is stacked on both and reuses their string machinery. Two small edits to their files:
WtfStringCreate.cppexposes its allocation and ref helpers.WtfStringSearch.cppis renamed so it no longer clashes with the newCStringtype.Source. Ported from pinned WebKit
c55364d53f97:UTF8Conversion.{h,cpp}StringImpl,StringView,WTFString,CStringExpected.h,RefCounted.h,JSONValues.{h,cpp}utf8.h/utf16.hmacrosEvery mangled name matches its declaration there.
Conversion modes. Lenient, strict and FFFD-replacing modes follow WebKit, including two quirks: a lone trailing lead surrogate is written as a raw triple in lenient mode, and FFFD mode retries in strict mode.
Layouts (static-asserted):
CString: a non-trivial pointer to a 16-byteCStringBufferheader.Expected<CString, UTF8ConversionError>: 16 bytes per pinnedExpected.h, withhasat offset 8, returned through the hidden pointer.Value: 24 bytes.ArrayBase: 40 bytes, with itsVectorat 24. The last deref calls the deleting destructor in vtable slot 1.Debt. New UTF-8 and JSON entries record the unverified console WTF/ICU versions. They also note that guests free
CStringbuffers through libSceNKWebKitfastFree, which relies on the shared allocation header. Throws replace WebKit's overruns, asserts and crashes: a full target buffer, an out-of-rangetryGetUtf8ForRange, a length aboveINT_MAX, a failedString::utf8, and null arguments. Counts are lowered and table rows removed.Left throwing:
JSONImpl::Value::escapeString, which needs aStringBuilderlayout.Tested
macOS 27 on Apple M1. The new registered tests
tests/WtfUtf8.cppandtests/WtfJson.cppare full-build tests and were not run: the full build does not run on macOS. A Linux or Windows run is needed.Harness. A temporary host harness, not committed, compiled the unchanged production sources with both test files. Expected values were derived by hand. It passed:
leaks --atExit: 0 leaksThe
WtfStringCreateandWtfStringSearchtests from #18420 and #18430 still pass with this change.Mutation check. All 6 hand mutations failed the harness:
Syntax.
clang++ -arch x86_64 -fsyntax-onlypasses on every changed .cpp.Overlap. No open PR implements these exports.
pr_overlap.pyflagged #17704 and #17722 (libwebrtc) only for a shared test-helper name, which was renamed.docs/dev/debt/libSceJsc.mdis possible.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
Summary by CodeRabbit
New Features
Tests
Documentation
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T16:12:37Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b7b403ba76:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_string_search_tests,jsc_wtf_utf8_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json,jsc_wtf_string_search):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass._ZNK3WTF10StringImpl10startsWithEPKS0_contains an inverted null checkreturn !prefix || StartsWith(text, Require(prefix, __func__), false);, which returnstruewhenprefixisnullptr. In WebKit WTF (StringImpl::startsWith(const StringImpl*)), a null prefix returnsfalse(prefix && startsWith(*prefix)). This bug causes every string to incorrectly report starting with null, and contradicts sibling functions in the same file (startsWithIgnoringASCIICaseat line 243 andendsWithat line 252) which correctly returnfalseon null pointers.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:00:42Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
4865bf9ba9:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T17:04:34Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b83b2129c0:tools/check_conventions.pypassed.jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cpp,core/libs/prx/libSceJsc/src/WtfJson.cpp,core/libs/prx/libSceJsc/src/WtfStringCreate.cpp,core/libs/prx/libSceJsc/src/WtfUtf8.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T12:39:15Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
71d6d8448d:tools/check_conventions.pypassed.jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cpp,core/libs/prx/libSceJsc/src/WtfJson.cpp,core/libs/prx/libSceJsc/src/WtfStringCreate.cpp,core/libs/prx/libSceJsc/src/WtfUtf8.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:14:24Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed UTF-8 and JSON implementations show no verified blocking defect; I did not read every changed file or run the full-build tests, so a formal approval is not justified.
What I ran
Reviewed head
71d6d8448da3edf3cf2487cb83641ebd1c634cabusing the prepared diff and repository reader. No tests or build commands were run.Results
Findings
Blocking
None verified in the code read.
Non-blocking
None.
Not verified
Read
description.md,commits.md,manifest.json,diff.patch, the changed source filesWtfUtf8.cpp,WtfJson.cpp,WtfStringAbi.hpp,WtfUtf8Exports.hpp, andWtfJsonExports.hpp, plus the changed-file listing. The manifest lists 19 changed files; the remaining 14 changed files were not read. The author reports a temporary host harness passed and syntax checks passed; those results were not independently run or verified.To get this to a good state
Nothing is required. Optional: run the registered UTF-8, JSON, and string creation tests on a supported full-build platform and review the remaining changed files.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T11:03:20Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0539d62df0:tools/check_conventions.pypassed.jsc_wtf_base64_tests,jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json,jsc_wtf_base64):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/include/WtfBase64Exports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfBase64.cpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cpp,core/libs/prx/libSceJsc/src/WtfJson.cpp,core/libs/prx/libSceJsc/src/WtfStringCreate.cpp,core/libs/prx/libSceJsc/src/WtfUtf8.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T11:04:37Z.
Review: COMMENTED
Reviewed — comments
The implementation has concrete null-buffer edge cases in the JSON array accessors and destruction path that need correction before these exports are safe to use.
What I ran
Reviewed head
0539d62df05e49921def7a28001aace6bef73425. Read the prepared description, commits, manifest, and relevant diff hunks, plusWtfJson.cpptest context throughrepo_read.py. No commands or tests were run; the description reports the registered full-build tests were not run.Results
Findings
Blocking
core/libs/prx/libSceJsc/src/WtfJson.cpp:805:end()unconditionally addssizetobuffer. An empty/default array with a null buffer causes undefined pointer arithmetic, even whensizeis zero. Returnnullptrfor a null buffer (or otherwise match the source implementation's empty-array behavior).core/libs/prx/libSceJsc/src/WtfJson.cpp:810: the destructor loops oversizeand indexesbufferwithout checking it. A valid empty array represented bybuffer == nullptrandsize == 0avoids the loop, but malformed or partially initialized state with positive size crashes. More materially, the tested empty-array case only has size zero; the implementation should guard the buffer before iteration to keep destruction safe for empty storage.Non-blocking
None.
Not verified
Tests, build, physical-console behavior, and the reported temporary host harness were not verified. Reviewed the description, commits, manifest and relevant diff hunks; the full changed-file set and excluded-file list were not read in full.
To get this to a good state
Correct the null-buffer handling in
end()and guard the array destruction loop, then run the registered JSON tests on a supported full-build platform.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T04:13:25Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e98c4fba85:tools/check_conventions.pypassed.jsc_wtf_base64_tests,jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_tests,nkwebkit_wtfstringimpldestroy_testsfailed to build.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T04:22:44Z.
Review: COMMENTED
Actionable comments posted: 2
7ef3115b-99b9-4099-b915-6bf17f6725c6Reviewing files that changed from the base of the PR and between
e1629f7e9aande98c4fba85.core/libs/prx/libSceJsc/CMakeLists.txtcore/libs/prx/libSceJsc/Export.cppcore/libs/prx/libSceJsc/LegacyExports.cppcore/libs/prx/libSceJsc/include/Api.hppcore/libs/prx/libSceJsc/include/InventoryExports.hppcore/libs/prx/libSceJsc/include/LegacyExports.hppcore/libs/prx/libSceJsc/include/WtfBase64Exports.hppcore/libs/prx/libSceJsc/include/WtfJsonExports.hppcore/libs/prx/libSceJsc/include/WtfStringCreateExports.hppcore/libs/prx/libSceJsc/include/WtfUtf8Exports.hppcore/libs/prx/libSceJsc/libSceJsc.hppcore/libs/prx/libSceJsc/src/WtfBase64.cppcore/libs/prx/libSceJsc/src/WtfJson.cppcore/libs/prx/libSceJsc/src/WtfStringAbi.hppcore/libs/prx/libSceJsc/src/WtfStringCreate.cppcore/libs/prx/libSceJsc/src/WtfStringSearch.cppcore/libs/prx/libSceJsc/src/WtfUtf8.cppcore/libs/prx/libSceJsc/tests/WtfBase64.cppcore/libs/prx/libSceJsc/tests/WtfJson.cppcore/libs/prx/libSceJsc/tests/WtfStringCreate.cppcore/libs/prx/libSceJsc/tests/WtfUtf8.cppcore/libs/prx/libSceNKWebKit/Export.cppcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppcore/libs/prx/libSceNKWebKit/include/WtfExports.hppcore/libs/prx/libSceNKWebKit/src/WtfString.cppcore/libs/prx/libSceNKWebKit/src/WtfStringAbi.hppcore/libs/prx/libSceNKWebKit/tests/WtfStringImplDestroy.cppdocs/dev/debt/changes/feat-jsc-wtf-cstring-json.mddocs/dev/debt/changes/feat-jsc-wtf-string-create.mddocs/dev/debt/changes/feat-libscejsc-wtf-small-functions.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T08:34:12Z.
Review: COMMENTED
Reviewed — comments
The UTF-8 and JSON additions have focused coverage, but the shared allocation code has an unchecked length calculation that can wrap for large strings.
What I ran
Reviewed head
e98c4fba85db1fb288bc2e83e71c3b090a820dc1againstmain. Read the prepared description, commit list, manifest, and diff, plus the changed UTF-8, JSON, string ABI, export, and test files listed under Not verified. No commands or tests were run; the description reports that the full-build tests were not run and that a temporary host harness passed.Results
Findings
Blocking
None.
Non-blocking
Utf8ForUTF16sizes its temporary buffer aslength * 3atcore/libs/prx/libSceJsc/src/WtfUtf8.cpp:251, without checking againstSIZE_MAX. On a 32-bit host, a sufficiently large string can wrap this multiplication, allocate too little space, and let conversion write past the vector. TheMaxLength / 3guard at line 251 uses a 32-bit limit and does not preventsize_toverflow on a 32-bit build. Add asize_toverflow guard before multiplying, or derive the allocation size with checked arithmetic.Not verified
core/libs/prx/libSceJsc/CMakeLists.txt,core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/include/WtfBase64Exports.hpp,core/libs/prx/libSceJsc/include/WtfJsonExports.hpp,core/libs/prx/libSceJsc/include/WtfStringCreateExports.hpp,core/libs/prx/libSceJsc/include/WtfUtf8Exports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfBase64.cpp,core/libs/prx/libSceJsc/src/WtfJson.cpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringCreate.cpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cpp,core/libs/prx/libSceJsc/src/WtfUtf8.cpp,core/libs/prx/libSceJsc/tests/WtfBase64.cpp,core/libs/prx/libSceJsc/tests/WtfJson.cpp,core/libs/prx/libSceJsc/tests/WtfStringCreate.cpp,core/libs/prx/libSceJsc/tests/WtfUtf8.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/WtfExports.hpp,core/libs/prx/libSceNKWebKit/src/WtfString.cpp,core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp,core/libs/prx/libSceNKWebKit/tests/WtfStringImplDestroy.cpp,docs/dev/debt/changes/feat-jsc-wtf-cstring-json.md,docs/dev/debt/changes/feat-jsc-wtf-string-create.md, anddocs/dev/debt/changes/feat-libscejsc-wtf-small-functions.md.core/libs/prx/libSceNKWebKit/Export.cppwas excluded as too large and was not read. No physical-console behavior was verified. Harness and convention-check results in the description are author-reported, not run here.To get this to a good state
Nothing is required. Optional: use checked arithmetic for the UTF-16 buffer-size calculation and run the registered full-build tests on a supported host.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T16:11:14Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ab33fddebc:tools/check_conventions.pypassed.jsc_wtf_base64_tests,jsc_wtf_json_tests,jsc_wtf_string_create_tests,jsc_wtf_utf8_tests,nkwebkit_wtfstringimpldestroy_testsbuilt cleanly.jsc_wtf_string_create,jsc_wtf_utf8,jsc_wtf_json,jsc_wtf_base64,nkwebkit_wtfstringimpldestroy):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/LegacyExports.cpp,core/libs/prx/libSceJsc/include/Api.hpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/include/LegacyExports.hpp,core/libs/prx/libSceJsc/include/WtfBase64Exports.hpp,core/libs/prx/libSceJsc/libSceJsc.hpp,core/libs/prx/libSceJsc/src/WtfBase64.cpp,core/libs/prx/libSceJsc/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfStringSearch.cpp,core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/WtfExports.hpp,core/libs/prx/libSceNKWebKit/src/WtfString.cpp,core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp,core/libs/prx/libSceJsc/src/WtfJson.cpp,core/libs/prx/libSceJsc/src/WtfStringCreate.cpp,core/libs/prx/libSceJsc/src/WtfUtf8.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass._ZNK3WTF8JSONImpl9ArrayBase3endEvunconditionally calculatesarray.buffer + array.size. Whenarray.bufferis null (e.g., an emptyArrayBaseinitialized with null buffer or empty capacity andsize == 0), performing pointer additionnullptr + 0causes undefined behavior in C++ (and would dereference a non-null pointer if size > 0 with null buffer). It must returnnullptrwhenarray.bufferis null._ZN3WTF8JSONImpl9ArrayBaseD2Evindexesarray.buffer[i]and callsJsc::WtfAbi::FreeBlock(array.buffer)without checking ifarray.bufferis null. Whilearray.size == 0skips the loop, passingnullptrto custom allocatorFreeBlockif not explicitly designed for null pointers is unsafe, and partial initialization wherearray.buffer == nullptrwitharray.size > 0dereferences null.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T16:25:01Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete because the large changed
libSceNKWebKit/Export.cppcould not be read, so a formal decision is not justified.What I ran
Read the prepared description, commit list, manifest, and diff for head
ab33fddebc93104728e017d23c2adc968334a6fd. No build or tests were run by this review.Results
Findings
Blocking
None verified in the inspected diff.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceNKWebKit/Export.cppwas excluded as too large; its changed behavior was therefore not reviewed. The inventory lists other changed files, but their full texts and relevant hunks were not inspected. The author reports temporary harness and syntax checks; those results were not independently run or confirmed here. The prepared file listing for exclusions was unavailable.To get this to a good state
Nothing is required. Optional point: review the excluded export changes and the remaining changed files before making a formal decision.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:31:17Z.
Review: COMMENTED
The exact head trial-merges cleanly onto
c1601e56d5, and a separate trial composition with current #18430 was clean. The current #18430 head is not an ancestor of this branch, so the stacked fixture results should identify the exact pair tested. Preserve theCStringand borrowed-string lifetime cases across the JSC/NKWebKit boundary. The debt entry correctly treats the console JSON object layout and deleting destructor slot as unverified. Please add clickable links to the pinned upstream commit in the adapted files’ attribution notices, per the repository rules.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.