Skip to content

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

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22781
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22781

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#22781, originally opened by milescoviello.

Source commit: 3f3fc83a8dd779176581f45de495df6c65b1787c. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid or unreadable hash-string input. These cases now produce an error instead of causing an unsafe read.

…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>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Six-character hash parsing

Layer / File(s) Summary
Guest-memory reads and parser validation
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
The parser uses HashCharacter to read the six encoded characters and check the seventh character. Existing character mapping and validation remain unchanged. The test checks that an invalid address causes an exception. The documentation describes the read behavior and exception cases.

Change: Bug fix

Merge Risk: Minimal · up to 3f3fc

This change makes the six-character hash parser throw an exception on unreadable guest strings instead of crashing the host. No actionable merge-blocking risk remains.

Security architecture risk: Minimal · up to 3f3fc

libSceNKWebKit now uses checked reads for hash input. A failed read is reported through the existing invalid-input exception path instead of faulting on a direct pointer access. The export signature and hash format are unchanged.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure change is limited to how this existing hash export handles reads from its caller-supplied pointer. The merge-base diff preserves the offsets, read limit, and output and does not change the neighboring privilege functions.

Trust Boundaries and Controls

  • observed — The copy helper checks the source address and whether the copy completes before the parser uses the byte. The underlying implementation can read from the current process, so copy success does not establish that the address belongs to the guest.

Resilience and Maintainability Implications

  • observed — The added test expects an exception for an unreadable pointer on the same export already tested with valid and malformed input. It covers the parser's failure path, not production guest dispatch.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 3
  • Waived: $0.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b13e8a5-b69b-4279-a650-0cad02b4132e
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 3f3fc83.

Files selected for processing: 3

  • 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

Limit details: You’ve used all 10 included reviews currently available.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 1 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 2 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 3 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 4 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 5 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 6 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 7 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 8 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 9 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 10 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 11 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 12 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 13 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 14 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 15 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 16 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 17 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 18 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 19 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md
PR 20 docs/dev/debt/changes/fix-nkwebkit-six-character-hash-guest-copy.md

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants