fix(libSceNKWebKit): read URL::user, password and protocolHostAndPort without the valid bit #24136

Closed
ToRaNek wants to merge 3 commits from upstream-pr/24136 into main
ToRaNek commented 2026-11-20 07:19:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ToRaNek on 2026-11-20T07:19:42Z.


What

URL::user, URL::password and URL::protocolHostAndPort began with a test of the URL's valid bit and returned a null String when it was clear. WebKit has no such test in any of the three (URL.cpp L170-L231; the same at e12a212a531a and c55364d53f97):

String URL::protocolHostAndPort() const
{
    if (!hasCredentials())
        return m_string.left(pathStart());
    ...
}

String URL::user() const
{
    return decodeEscapeSequencesFromParsedURL(encodedUser());
}

They read the offsets and the string whatever the bit says. For a URL the parser rejected, the offsets are all zero and the string is the text as given, so the results are:

URL Call WebKit before
invalid, text not a url user() empty string, not null null string
invalid, text not a url protocolHostAndPort() empty string, not null null string
invalid, text not a url password() null string null string
null string all three null string null string

The difference is what isNull() answers on the result. A caller that only tests isEmpty() sees no change.

The three exports now return a null string only when the URL's string is null, and otherwise go on as WebKit does. password() is changed with the other two so the three stay alike; its result for a rejected URL was already right, because a URL without a password gives a null view.

This is stacked on #22472, which rewrites the first lines of the same three functions to read the URL through a checked copy; the first commit of this branch merges it.

Tested

Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON.

  • core/libs/prx/libSceNKWebKit/tests/WtfValues.cpp: a rejected URL with the text not a url (empty and not null from user and protocolHostAndPort, null from password), a URL with a null string (null from all three), and the existing hand-built URL whose valid bit is clear but whose offsets are set, which now gives what its offsets say, as the source would.
  • Red: with the new test file on main fd7fe562ed plus #22472, nkwebkit_wtfvalues fails at the first check on the rejected URL.
  • Green: with the fix, after a full rebuild ctest -R "^nkwebkit_" passes 161 of 161, #22472's new test included.
  • python tools/check_conventions.py --base origin/main passes.
  • python tools/pr_overlap.py --branch fix/nkwebkit-url-credentials-ignore-validity: no overlap with open pull requests.

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: #22472
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5409443363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24136). Originally posted by [ToRaNek](https://github.com/ToRaNek) on 2026-11-20T07:19:42Z. --- ### What `URL::user`, `URL::password` and `URL::protocolHostAndPort` began with a test of the URL's valid bit and returned a null `String` when it was clear. WebKit has no such test in any of the three ([`URL.cpp` L170-L231](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/URL.cpp#L170-L231); the same at `e12a212a531a` and `c55364d53f97`): ```cpp String URL::protocolHostAndPort() const { if (!hasCredentials()) return m_string.left(pathStart()); ... } String URL::user() const { return decodeEscapeSequencesFromParsedURL(encodedUser()); } ``` They read the offsets and the string whatever the bit says. For a URL the parser rejected, the offsets are all zero and the string is the text as given, so the results are: | URL | Call | WebKit | before | |---|---|---|---| | invalid, text `not a url` | `user()` | empty string, not null | null string | | invalid, text `not a url` | `protocolHostAndPort()` | empty string, not null | null string | | invalid, text `not a url` | `password()` | null string | null string | | null string | all three | null string | null string | The difference is what `isNull()` answers on the result. A caller that only tests `isEmpty()` sees no change. The three exports now return a null string only when the URL's string is null, and otherwise go on as WebKit does. `password()` is changed with the other two so the three stay alike; its result for a rejected URL was already right, because a URL without a password gives a null view. This is stacked on #22472, which rewrites the first lines of the same three functions to read the URL through a checked copy; the first commit of this branch merges it. ### Tested Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. - `core/libs/prx/libSceNKWebKit/tests/WtfValues.cpp`: a rejected URL with the text `not a url` (empty and not null from `user` and `protocolHostAndPort`, null from `password`), a URL with a null string (null from all three), and the existing hand-built URL whose valid bit is clear but whose offsets are set, which now gives what its offsets say, as the source would. - Red: with the new test file on `main` `fd7fe562ed` plus #22472, `nkwebkit_wtfvalues` fails at the first check on the rejected URL. - Green: with the fix, after a full rebuild `ctest -R "^nkwebkit_"` passes 161 of 161, #22472's new test included. - `python tools/check_conventions.py --base origin/main` passes. - `python tools/pr_overlap.py --branch fix/nkwebkit-url-credentials-ignore-validity`: no overlap with open pull requests. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #22472 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-20 07:43:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T07:43:43Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 06d92a2638:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_wtfpersistenceurlguestpointers_tests, nkwebkit_wtfvalues_tests built cleanly.
  • CTest (nkwebkit_wtfpersistenceurlguestpointers, nkwebkit_wtfvalues):
    1/2 Test #4814: nkwebkit_wtfvalues ........................   Passed    0.06 sec
    2/2 Test #4807: nkwebkit_wtfpersistenceurlguestpointers ...   Passed    0.10 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/WtfValues.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #4807: nkwebkit_wtfpersistenceurlguestpointers ...***Exception: SegFault  0.37 sec
    2/2 Test #4814: nkwebkit_wtfvalues ........................Subprocess aborted***Exception:   0.43 sec
    0% tests passed, 2 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified _ZNK3WTF3URL19protocolHostAndPortEv, _ZNK3WTF3URL4userEv, and _ZNK3WTF3URL8passwordEv in WtfValues.cpp: correctly removed the URL valid bit check (!(url.bits & 1)) while preserving the null string check (!url.impl) to match upstream WebKit URL.cpp behavior.
    • Verified guest memory safety in WtfValues.cpp: self and protocol pointers are validated via LoadURL, GuestCopyIn_nid_no_patch, GuestWritable_nid_no_patch, and CopyGuestCString, throwing std::invalid_argument on null or falling back to NotImplementedAt_nid_no_patch on invalid guest memory.
    • Verified Encoder and Decoder guest pointer serialization/deserialization: LoadEncoder, StoreEncoder, and Decoder verifyChecksum adhere strictly to bounds checks and handle guest memory transitions safely without leaking allocations or corrupting SHA1 state.
    • Verified WtfValues.cpp and WtfPersistenceUrlGuestPointers.cpp unit tests: new test coverage comprehensively exercises valid, unparsed/invalid URLs, null strings, credentials parsing, and unmapped/read-only memory fault handling.
    • Verified compliance with AGENTS.md conventions: no comments added in code, no fake success stubs, no special-casing of game IDs/traces, and clean check_conventions / diff-check results.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5989149862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24136#pullrequestreview-5989149862). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T07:43:43Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `06d92a2638`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_wtfpersistenceurlguestpointers_tests`, `nkwebkit_wtfvalues_tests` built cleanly. - **CTest** (`nkwebkit_wtfpersistenceurlguestpointers`, `nkwebkit_wtfvalues`): ``` 1/2 Test #4814: nkwebkit_wtfvalues ........................ Passed 0.06 sec 2/2 Test #4807: nkwebkit_wtfpersistenceurlguestpointers ... Passed 0.10 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #4807: nkwebkit_wtfpersistenceurlguestpointers ...***Exception: SegFault 0.37 sec 2/2 Test #4814: nkwebkit_wtfvalues ........................Subprocess aborted***Exception: 0.43 sec 0% tests passed, 2 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Verified _ZNK3WTF3URL19protocolHostAndPortEv, _ZNK3WTF3URL4userEv, and _ZNK3WTF3URL8passwordEv in WtfValues.cpp: correctly removed the URL valid bit check (!(url.bits & 1)) while preserving the null string check (!url.impl) to match upstream WebKit URL.cpp behavior. - Verified guest memory safety in WtfValues.cpp: self and protocol pointers are validated via LoadURL, GuestCopyIn_nid_no_patch, GuestWritable_nid_no_patch, and CopyGuestCString, throwing std::invalid_argument on null or falling back to NotImplementedAt_nid_no_patch on invalid guest memory. - Verified Encoder and Decoder guest pointer serialization/deserialization: LoadEncoder, StoreEncoder, and Decoder verifyChecksum adhere strictly to bounds checks and handle guest memory transitions safely without leaking allocations or corrupting SHA1 state. - Verified WtfValues.cpp and WtfPersistenceUrlGuestPointers.cpp unit tests: new test coverage comprehensively exercises valid, unparsed/invalid URLs, null strings, credentials parsing, and unmapped/read-only memory fault handling. - Verified compliance with AGENTS.md conventions: no comments added in code, no fake success stubs, no special-casing of game IDs/traces, and clean check_conventions / diff-check results. Looks Good To Me
MarcZX10 commented 2026-11-20 07:49:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:49:56Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the notes below are optional.

What I ran

Reviewed head 06d92a26386fbd4c0ebd1f17aab81fb99c10ddb2 and the prepared diff. No test commands were run; the test results in the PR description are author-reported.

Results

Check Result Note
Diff and changed code passed Three changed files read
Tests not run PR reports Windows test results
Build and conventions not run PR reports successful checks

Findings

Blocking

None.

Non-blocking

None.

Not verified

The added guest-pointer tests and changed behavior were not executed in this review. The PR description reports 161 passing nkwebkit tests and a passing conventions check; these results were not independently verified. Files read: core/libs/prx/libSceNKWebKit/src/WtfValues.cpp, core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp, core/libs/prx/libSceNKWebKit/tests/WtfValues.cpp, core/libs/prx/libSceNKWebKit/CMakeLists.txt, core/libs/prx/libc/src/General.cpp, plus review/description.md, review/commits.md, review/manifest.json, and review/diff.patch. The reviewed changed files were all included in the prepared bundle; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5989206972 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24136#pullrequestreview-5989206972). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T07:49:56Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the notes below are optional. ## What I ran Reviewed head `06d92a26386fbd4c0ebd1f17aab81fb99c10ddb2` and the prepared diff. No test commands were run; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Three changed files read | | Tests | not run | PR reports Windows test results | | Build and conventions | not run | PR reports successful checks | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The added guest-pointer tests and changed behavior were not executed in this review. The PR description reports 161 passing `nkwebkit` tests and a passing conventions check; these results were not independently verified. Files read: `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp`, `core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp`, `core/libs/prx/libSceNKWebKit/tests/WtfValues.cpp`, `core/libs/prx/libSceNKWebKit/CMakeLists.txt`, `core/libs/prx/libc/src/General.cpp`, plus `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch`. The reviewed changed files were all included in the prepared bundle; no changed files were excluded. ## To get this to a good state Nothing is required.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!24136
No description provided.