Repository navigation
fix(libSceNKWebKit): read WTF::sixCharacterHashStringToInteger's characters through checked guest copies - #22781
Conversation
…acters through checked guest copies sixCharacterHashStringToInteger read the caller's characters and the terminator through the guest pointer, so an unmapped or unreadable string crashed the host. Each character is now read with a one-byte GuestCopyIn_nid_no_patch, in the same order and stopping at the same invalid character as before, so a short string at the end of a readable page still fails as an invalid hash. A string that can't be read throws std::invalid_argument, as a null or malformed one does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3f3fc83a8d:
- Conventions:
tools/check_conventions.pypassed. - Build:
nkwebkit_wtf_testsbuilt cleanly. - CTest (
nkwebkit_wtf):1/1 Test #4581: nkwebkit_wtf ..................... Passed 0.14 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceNKWebKit/src/WtfPrimitives.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4581: nkwebkit_wtf .....................***Exception: SegFault 0.13 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified GuestCopyIn_nid_no_patch error handling in HashCharacter: safely catches unmapped/faulting guest pointers and throws std::invalid_argument as specified in debt documentation
- Verified 6-character loop logic and character set mapping ([A-Z], [a-z], [0-9]) along with null-terminator enforcement at index 6
- Verified that invalid characters or short strings throw std::invalid_argument before reading out-of-bounds trailing memory
- Verified technical debt fragment docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md matches AGENTS.md conventions and accurately documents the host-safety fallback
- Verified test coverage in core/libs/prx/libSceNKWebKit/tests/Wtf.cpp exercising invalid unmapped guest pointer (0x10) alongside valid, short, and malformed cases
Looks Good To Me
|
Thanks @PrivacyOnion for the GCC 13.3 run and the negative control. I've added it to the Tested section, linked to your review. |
|
Windows result for head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release,
AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
|
Thanks @maskym for the Windows run. I've added it to the Tested section, linked to your comment. |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
Thanks @kiwe147 for including this one in the batch. The |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reviewed change at 3f3fc83a8dd779176581f45de495df6c65b1787c safely copies each hash byte through the guest memory helper; no verified blocking defect was found.
What I ran
- Read the prepared diff and all three changed files, plus the guest-copy declaration and implementation.
- No commands or tests were run;
repo_read.pywas used to inspect the pinned head.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | All three reviewed |
| Tests | not run | Author reports nkwebkit_wtf passes |
| Build and runtime | not run | No local execution |
Findings
Blocking
None.
Non-blocking
None.
Not verified
- Tests and build were not run independently; test results in the description are author-reported.
- Console behavior for inaccessible strings was not measured, as the change record states.
- Read:
core/libs/prx/libSceNKWebKit/src/WtfPrimitives.cpp,core/libs/prx/libSceNKWebKit/tests/Wtf.cpp,docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md,core/libs/prx/libc/include/General.hpp, andcore/libs/prx/libc/src/General.cpp. All files listed as reviewed in the manifest were read; no exclusions were listed.
To get this to a good state
Nothing is required.
What
WTF::sixCharacterHashStringToIntegerread the caller's six characters and the terminator through the guest pointer, so an unmapped or unreadable string crashed the host.Changes:
GuestCopyIn_nid_no_patch, in the same order and stopping at the same invalid character as before. So a short string that ends near the end of a readable page still fails as an invalid hash rather than as unreadable.std::invalid_argument, as a null or malformed one does.Results for readable strings are unchanged. The function reads at most 7 bytes, so the per-byte copies cost nothing measurable.
Tested
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:nkwebkit_wtfgains an unmapped string (0x10) forsixCharacterHashStringToInteger, which throws. The existing checks of valid, short, long and malformed hashes still pass.nkwebkit_wtfpasses, 3 runs.main'sWtfPrimitives.cppand the new check,nkwebkit_wtfends infatal SIGSEGV (code 1) at address 0x0000000000000010.nkwebkit_wtfpasses, and withmain'sWtfPrimitives.cppand the new check it ends in a segfault.3f3fc83a8dmerged intomain168921678f(Windows 11, i7-12700K, WinLibs GCC 15.2.0, Release):nkwebkit_wtfpasses 3 of 3 runs.git merge-treeagainstmainis clean. feat(libSceNKWebKit): implement WTF FileSystemImpl hardLink, createSymbolicLink and appendFileContentsToFileHandle #19823, feat(libSceNKWebKit): implement WTF FileSystemImpl existence, delete and volume helpers over the guest filesystem #19822 and feat(libSceNKWebKit): implement WTF::GregorianDateTime constructors #14478 also edittests/Wtf.cpp, none of them this check;git merge-treeof this branch with each is clean.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for this fragment.3f3fc83a8d, applied with other PRs ontomainfd4aeed483(one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer: the 3guest_wtf_data_log*tests pass on an NVIDIA GeForce RTX 3080 (driver 621.24).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)