Skip to content

fix(libSceNKWebKit): read WTF::sixCharacterHashStringToInteger's characters through checked guest copies - #22781

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/nkwebkit-six-character-hash-guest-copy
Dec 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/nkwebkit-six-character-hash-guest-copy

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

WTF::sixCharacterHashStringToInteger read the caller's six characters and the terminator through the guest pointer, so an unmapped or unreadable string crashed the host.

Changes:

  • Each character is 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 that ends near the end of a readable page still fails as an invalid hash rather than as unreadable.
  • A string that can't be read throws 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:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…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 PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3f3fc83a8d:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_wtf_tests built 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.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4581: nkwebkit_wtf .....................***Exception: SegFault  0.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • 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

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @PrivacyOnion for the GCC 13.3 run and the negative control. I've added it to the Tested section, linked to your review.

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 3f3fc83a8d, merged alone into main 168921678f (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

nkwebkit_wtf, the test this PR adds or extends, passes 3 of 3 runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @maskym for the Windows run. I've added it to the Tested section, linked to your comment.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 3f3fc83a8d, applied with git apply on main fd4aeed483 together with the other 27 PRs of one batch (#11049, #20072, #20406, #22100, #22892, #23774, #24199, #24495, #15314, #21180, #21221, #21486, #22597, #22839, #22895, #23550, #24672, #14573, #16873, #17113, #17879, #19183, #20057, #22066, #22219, #22958, #24478). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_wtf_data_log, guest_wtf_data_log_install_first, guest_wtf_data_log_install_null (3 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 8 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked, agc_storage_write_back_host_retile. Traced to other PRs of the batch, each by reverting it and testing again: #21486 (agc_driver_graphics, agc_graphics_profile_draw), #24672 (guest_kernel_sys_neo_mode); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_indexed_draw. The 2125 agc_/video tests on the iGPU have 5 failing: agc_driver_graphics, agc_driver_stencil_plane_memory, agc_driver_store_over_untracked, agc_graphics_profile_draw, agc_storage_write_back_host_retile (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @kiwe147 for including this one in the batch. The guest_wtf_data_log* tests passing is a useful Windows data point, and I added it to the description, noted as a combined batch tree rather than this PR alone.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py was 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, and core/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants