fix(libSceNKWebKit): copy WTF::Persistence and WTF::URL guest pointers safely #22472

Open
domx4q wants to merge 8 commits from upstream-pr/22472 into main
domx4q commented 2026-11-17 17:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by domx4q on 2026-11-17T17:29:02Z.


What

WtfValues.cpp in libSceNKWebKit read and wrote guest WTF::Persistence::Encoder, WTF::Persistence::Decoder and WTF::URL objects directly. They now copy guest memory in, compute on host copies and copy results out. This follows the merged WTF::MediaTime and WebCore::Region fixes in this library: GuestCopyIn_nid_no_patch, GuestCopyOut_nid_no_patch, GuestWritable_nid_no_patch, and failure through NotImplementedAt_nid_no_patch.

  • Encoder constructor, destructor, encodeChecksum and the ten numeric operator<< exports:
    • The 16-byte header (buffer, capacity, size) and the SHA-1 state are copied in once per call. Before that, the whole 4216-byte Encoder is checked writable.
    • Encoded bytes are written to the buffer with one GuestCopyOut_nid_no_patch per call. That buffer is the guest inline buffer, or the library's fastMalloc buffer after growth.
    • When the buffer grows, the old contents are copied out of the guest with GuestCopyIn_nid_no_patch. The new buffer and capacity (with the unchanged size) are written to the guest header before the old buffer is freed; if that write fails, the new buffer is freed and the old one stays in place. A later failure in the same call therefore leaves the header owning a live buffer that holds the old bytes.
    • Bytes are written to the buffer with GuestCopyOut_nid_no_patch and hashed from the host value.
    • Header and SHA-1 state are written back at the end. The destructor reads and clears only the buffer pointer.
    • The String and CString coders copy the String/CString pointer, the StringImpl/CStringBuffer header and the whole payload into host memory with GuestCopyIn_nid_no_patch before touching the encoder. Only then do they load the encoder once, append length, 8-bit flag (String only) and payload, and store it once. A payload or header that cannot be read fails with the encoder header, buffer and SHA-1 state unchanged.
  • Decoder::bufferIsLargeEnoughToContain and verifyChecksum: the Decoder is copied in. The 20 checksum bytes are read from the guest data buffer with GuestCopyIn_nid_no_patch, and the updated Decoder is written back once.
  • URL::protocolIs(const char*): the guest C string is read in 4 KiB chunks that never cross a page, and the host allocation grows only by bytes already read. The guest URL is copied into a host URL with GuestCopyIn_nid_no_patch before the StringView overload runs. Before, it called strlen on the guest pointer and passed the guest URL straight to the overload.
  • URL::removeQueryAndFragmentIdentifier, hostAndPort, isMatchingDomain, protocolHostAndPort, user and password: the 40-byte URL is copied in, and the host copy goes to the host, encodedUser and encodedPassword accessors. removeQueryAndFragmentIdentifier releases the old string only after the truncated URL is written back. A read-only URL keeps its string and refcount.

Encoded bytes, checksums and URL results for valid inputs are unchanged. The test compares a page-backed encoder against a host encoder byte for byte, including growth past the 4096-byte inline buffer. Null this still throws std::invalid_argument, and a null Encoder in the destructor is still a no-op.

The string value exports of the same file are in a separate PR (fix/nkwebkit-wtf-string-values-guest-pointers). The two branches touch different hunks and merge cleanly (git merge-tree).

False positives left unchanged: tools/guest_pointer_audit.py libSceNKWebKit still lists the ten Encoder::operator<< exports as self (dereference). That hit is the return *self; of the reference return, and nothing is read. The merged MediaTime::operator= keeps the same hit. StringImpl and CStringBuffer objects behind URL are allocated by the library and stay host objects, like Region::Shape in the merged Region fix; the String and CString coders read theirs with GuestCopyIn_nid_no_patch.

No debt change: no debt entry describes the old behaviour.

Tested

Arch Linux, GCC, Release (-DBUILD_TESTING=ON).

  • New nkwebkit_wtfpersistenceurlguestpointers (tests/WtfPersistenceUrlGuestPointers.cpp, under 0.1 s):
    • every changed export with an unreadable this (0x10);
    • read-only Encoder, Decoder and URL pages, checked unchanged after the failure;
    • a Decoder whose data pointer cannot be read;
    • a protocol string that ends at a PROT_NONE page without a terminator, and one that crosses a page boundary;
    • protocolIs(const char*) with this on a PROT_NONE page, with a URL that runs into a PROT_NONE page, and with a valid URL that ends exactly at a page boundary;
    • page-backed encoders compared byte for byte (buffer and SHA-1 state) with host encoders, for a short payload and a 5000-byte payload that grows past the inline buffer;
    • failing String and CString encodes, each with no prefix, a short prefix and a 5000-byte prefix that already grew the buffer: an 8-bit String payload of 5000 and 3 bytes and a 16-bit one of 3 characters on a PROT_NONE page, a String whose StringImpl is on a PROT_NONE page, a CString payload of 5000 and 3 bytes running into a PROT_NONE page, and a CString whose buffer header is on a PROT_NONE page. The whole 4216-byte guest Encoder and its buffer are byte-identical after the failure, and a following String encode and operator<< give the same bytes and SHA-1 state as a fresh host encoder that saw only the prefix and those valid encodes;
    • checksum verification of data that ends at a guard page;
    • valid URL results from a read-only page;
    • removeQueryAndFragmentIdentifier on a writable page.
  • ctest --test-dir build -R 'public_headers|nkwebkit' -j 4: 187/187 passed (includes the existing nkwebkit_wtfvalues behaviour tests).
  • Mutation checks, each restored afterwards:
    • the previous EncoderAppendBytes, hashing the payload before copying it: segfault;
    • the String/CString coders as of 709b054f57 (length and 8-bit flag appended before the payload is read): check failed at line 120 (wrong failing export), and with only the failed-encode tests run, check failed at line 167 (guest Encoder changed after the failed encode);
    • LoadEncoder using memcpy: segfault;
    • LoadURL reading *source directly: segfault;
    • verifyChecksum reading the checksum bytes with memcpy: segfault;
    • protocolIs copying the guest string with std::string assignment: segfault;
    • protocolIs(const char*) passing the guest URL to the StringView overload without a host copy: segfault.
  • python3 tools/progress.py --root . --module libSceNKWebKit: 3308 done on both origin/main and this branch.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.

Overlap

  • python3 tools/pr_overlap.py --names for all 33 WtfValues.cpp exports listed by the audit: all implemented on main in libSceNKWebKit, no open PR edits them.
  • python3 tools/pr_overlap.py --branch fix/nkwebkit-wtf-persistence-url-guest-pointers: only #24136, which is stacked on this PR and carries this branch's tests/WtfPersistenceUrlGuestPointers.cpp; no other overlap.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5361758146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472). Originally posted by [domx4q](https://github.com/domx4q) on 2026-11-17T17:29:02Z. --- ### What `WtfValues.cpp` in libSceNKWebKit read and wrote guest `WTF::Persistence::Encoder`, `WTF::Persistence::Decoder` and `WTF::URL` objects directly. They now copy guest memory in, compute on host copies and copy results out. This follows the merged `WTF::MediaTime` and `WebCore::Region` fixes in this library: `GuestCopyIn_nid_no_patch`, `GuestCopyOut_nid_no_patch`, `GuestWritable_nid_no_patch`, and failure through `NotImplementedAt_nid_no_patch`. - `Encoder` constructor, destructor, `encodeChecksum` and the ten numeric `operator<<` exports: - The 16-byte header (`buffer`, `capacity`, `size`) and the SHA-1 state are copied in once per call. Before that, the whole 4216-byte `Encoder` is checked writable. - Encoded bytes are written to the buffer with one `GuestCopyOut_nid_no_patch` per call. That buffer is the guest inline buffer, or the library's `fastMalloc` buffer after growth. - When the buffer grows, the old contents are copied out of the guest with `GuestCopyIn_nid_no_patch`. The new `buffer` and `capacity` (with the unchanged `size`) are written to the guest header before the old buffer is freed; if that write fails, the new buffer is freed and the old one stays in place. A later failure in the same call therefore leaves the header owning a live buffer that holds the old bytes. - Bytes are written to the buffer with `GuestCopyOut_nid_no_patch` and hashed from the host value. - Header and SHA-1 state are written back at the end. The destructor reads and clears only the `buffer` pointer. - The `String` and `CString` coders copy the `String`/`CString` pointer, the `StringImpl`/`CStringBuffer` header and the whole payload into host memory with `GuestCopyIn_nid_no_patch` before touching the encoder. Only then do they load the encoder once, append length, 8-bit flag (`String` only) and payload, and store it once. A payload or header that cannot be read fails with the encoder header, buffer and SHA-1 state unchanged. - `Decoder::bufferIsLargeEnoughToContain` and `verifyChecksum`: the `Decoder` is copied in. The 20 checksum bytes are read from the guest data buffer with `GuestCopyIn_nid_no_patch`, and the updated `Decoder` is written back once. - `URL::protocolIs(const char*)`: the guest C string is read in 4 KiB chunks that never cross a page, and the host allocation grows only by bytes already read. The guest `URL` is copied into a host `URL` with `GuestCopyIn_nid_no_patch` before the `StringView` overload runs. Before, it called `strlen` on the guest pointer and passed the guest `URL` straight to the overload. - `URL::removeQueryAndFragmentIdentifier`, `hostAndPort`, `isMatchingDomain`, `protocolHostAndPort`, `user` and `password`: the 40-byte `URL` is copied in, and the host copy goes to the `host`, `encodedUser` and `encodedPassword` accessors. `removeQueryAndFragmentIdentifier` releases the old string only after the truncated URL is written back. A read-only URL keeps its string and refcount. Encoded bytes, checksums and URL results for valid inputs are unchanged. The test compares a page-backed encoder against a host encoder byte for byte, including growth past the 4096-byte inline buffer. Null `this` still throws `std::invalid_argument`, and a null `Encoder` in the destructor is still a no-op. The string value exports of the same file are in a separate PR (`fix/nkwebkit-wtf-string-values-guest-pointers`). The two branches touch different hunks and merge cleanly (`git merge-tree`). False positives left unchanged: `tools/guest_pointer_audit.py libSceNKWebKit` still lists the ten `Encoder::operator<<` exports as `self (dereference)`. That hit is the `return *self;` of the reference return, and nothing is read. The merged `MediaTime::operator=` keeps the same hit. `StringImpl` and `CStringBuffer` objects behind `URL` are allocated by the library and stay host objects, like `Region::Shape` in the merged `Region` fix; the `String` and `CString` coders read theirs with `GuestCopyIn_nid_no_patch`. No debt change: no debt entry describes the old behaviour. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Arch Linux, GCC, Release (`-DBUILD_TESTING=ON`). - New `nkwebkit_wtfpersistenceurlguestpointers` (`tests/WtfPersistenceUrlGuestPointers.cpp`, under 0.1 s): - every changed export with an unreadable `this` (`0x10`); - read-only `Encoder`, `Decoder` and `URL` pages, checked unchanged after the failure; - a `Decoder` whose data pointer cannot be read; - a protocol string that ends at a `PROT_NONE` page without a terminator, and one that crosses a page boundary; - `protocolIs(const char*)` with `this` on a `PROT_NONE` page, with a `URL` that runs into a `PROT_NONE` page, and with a valid `URL` that ends exactly at a page boundary; - page-backed encoders compared byte for byte (buffer and SHA-1 state) with host encoders, for a short payload and a 5000-byte payload that grows past the inline buffer; - failing `String` and `CString` encodes, each with no prefix, a short prefix and a 5000-byte prefix that already grew the buffer: an 8-bit `String` payload of 5000 and 3 bytes and a 16-bit one of 3 characters on a `PROT_NONE` page, a `String` whose `StringImpl` is on a `PROT_NONE` page, a `CString` payload of 5000 and 3 bytes running into a `PROT_NONE` page, and a `CString` whose buffer header is on a `PROT_NONE` page. The whole 4216-byte guest `Encoder` and its buffer are byte-identical after the failure, and a following `String` encode and `operator<<` give the same bytes and SHA-1 state as a fresh host encoder that saw only the prefix and those valid encodes; - checksum verification of data that ends at a guard page; - valid `URL` results from a read-only page; - `removeQueryAndFragmentIdentifier` on a writable page. - `ctest --test-dir build -R 'public_headers|nkwebkit' -j 4`: 187/187 passed (includes the existing `nkwebkit_wtfvalues` behaviour tests). - Mutation checks, each restored afterwards: - the previous `EncoderAppendBytes`, hashing the payload before copying it: segfault; - the `String`/`CString` coders as of 709b054f57 (length and 8-bit flag appended before the payload is read): `check failed at line 120` (wrong failing export), and with only the failed-encode tests run, `check failed at line 167` (guest `Encoder` changed after the failed encode); - `LoadEncoder` using `memcpy`: segfault; - `LoadURL` reading `*source` directly: segfault; - `verifyChecksum` reading the checksum bytes with `memcpy`: segfault; - `protocolIs` copying the guest string with `std::string` assignment: segfault; - `protocolIs(const char*)` passing the guest `URL` to the `StringView` overload without a host copy: segfault. - `python3 tools/progress.py --root . --module libSceNKWebKit`: 3308 done on both `origin/main` and this branch. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. ### Overlap - `python3 tools/pr_overlap.py --names` for all 33 `WtfValues.cpp` exports listed by the audit: all implemented on `main` in libSceNKWebKit, no open PR edits them. - `python3 tools/pr_overlap.py --branch fix/nkwebkit-wtf-persistence-url-guest-pointers`: only #24136, which is stacked on this PR and carries this branch's `tests/WtfPersistenceUrlGuestPointers.cpp`; no other overlap. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
PrivacyOnion commented 2026-11-17 17:33:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T17:33:49Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 5b71407663:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_wtfpersistenceurlguestpointers_tests built cleanly.
  • CTest (nkwebkit_wtfpersistenceurlguestpointers):
    1/1 Test #4525: nkwebkit_wtfpersistenceurlguestpointers ...   Passed    0.09 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/WtfValues.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4525: nkwebkit_wtfpersistenceurlguestpointers ...***Exception: SegFault  0.62 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified LoadEncoder / StoreEncoder / EncoderEnsure / EncoderAppendNum / EncoderAppendBytes properly validate guest buffers, handle dynamic reallocation with fastMalloc/fastFree, and preserve inline buffer vs heap buffer semantics.
    • Verified Decoder::bufferIsLargeEnoughToContain and verifyChecksum bounds checks against buffer overflow and unreadable guest addresses via GuestCopyIn_nid_no_patch and GuestWritable_nid_no_patch.
    • Verified CopyGuestCString page-boundary chunking logic in URL::protocolIs ensures no read overrun beyond page limits and safely finds null terminators.
    • Verified LoadURL and URL mutation methods (removeQueryAndFragmentIdentifier, hostAndPort, isMatchingDomain, protocolHostAndPort, user, password) properly copy guest URL in/out and retain/release StringImpl references safely without leaking.
    • Verified compliance with AGENTS.md: no forbidden comments, proper NotImplementedAt_nid_no_patch invocations on failure paths, and clean CTest execution across test cases.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5943450574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-5943450574). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T17:33:49Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `5b71407663`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_wtfpersistenceurlguestpointers_tests` built cleanly. - **CTest** (`nkwebkit_wtfpersistenceurlguestpointers`): ``` 1/1 Test #4525: nkwebkit_wtfpersistenceurlguestpointers ... Passed 0.09 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4525: nkwebkit_wtfpersistenceurlguestpointers ...***Exception: SegFault 0.62 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified LoadEncoder / StoreEncoder / EncoderEnsure / EncoderAppendNum / EncoderAppendBytes properly validate guest buffers, handle dynamic reallocation with fastMalloc/fastFree, and preserve inline buffer vs heap buffer semantics. - Verified Decoder::bufferIsLargeEnoughToContain and verifyChecksum bounds checks against buffer overflow and unreadable guest addresses via GuestCopyIn_nid_no_patch and GuestWritable_nid_no_patch. - Verified CopyGuestCString page-boundary chunking logic in URL::protocolIs ensures no read overrun beyond page limits and safely finds null terminators. - Verified LoadURL and URL mutation methods (removeQueryAndFragmentIdentifier, hostAndPort, isMatchingDomain, protocolHostAndPort, user, password) properly copy guest URL in/out and retain/release StringImpl references safely without leaking. - Verified compliance with AGENTS.md: no forbidden comments, proper NotImplementedAt_nid_no_patch invocations on failure paths, and clean CTest execution across test cases. Looks Good To Me
MarcZX10 commented 2026-11-23 07:06:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T07:06:12Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: copy the guest URL into host memory before delegating from the protocolIs(const char*) overload.

What I ran

Reviewed head 5b7140766399c64194cc396b5a6c614906c169f6. I did not run commands or tests; the PR description reports the author’s test results.

Results

Check Result Note
Changed code review failed One guest-pointer defect
Tests not run Results are author-reported
Negative control not run No test mutation performed

Findings

Blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:683 passes the original guest self pointer to the StringView overload. That overload calls Checked(self), which accesses the URL object directly, so an unreadable guest URL can still fault instead of being handled through GuestCopyIn_nid_no_patch. Load the URL into a host copy and pass that copy to the overload. The new tests cover an unreadable protocol string, but pass a host URL object, so they do not catch this case. Changed call at the reviewed commit · Delegated overload

Non-blocking

None.

Sources

Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and both changed files: core/libs/prx/libSceNKWebKit/src/WtfValues.cpp and core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp. Also read the delegated overload in core/libs/prx/libSceNKWebKit/src/WtfString.cpp.

Not verified

Tests, builds, and runtime behavior were not run in this review. The description reports tests on Arch Linux with GCC Release, including 187 passing CTest cases and mutation checks; these results were not independently verified. No changed files were excluded from review.

To get this to a good state

Copy the guest URL into a host-side URL before calling the StringView overload, and add coverage for an unreadable self pointer to this overload. Rerun the reported targeted test and CTest checks on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017663931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6017663931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T07:06:12Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: copy the guest `URL` into host memory before delegating from the `protocolIs(const char*)` overload. ## What I ran Reviewed head `5b7140766399c64194cc396b5a6c614906c169f6`. I did not run commands or tests; the PR description reports the author’s test results. ## Results | Check | Result | Note | |---|---|---| | Changed code review | failed | One guest-pointer defect | | Tests | not run | Results are author-reported | | Negative control | not run | No test mutation performed | ## Findings ### Blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:683` passes the original guest `self` pointer to the `StringView` overload. That overload calls `Checked(self)`, which accesses the URL object directly, so an unreadable guest URL can still fault instead of being handled through `GuestCopyIn_nid_no_patch`. Load the URL into a host copy and pass that copy to the overload. The new tests cover an unreadable protocol string, but pass a host URL object, so they do not catch this case. [Changed call at the reviewed commit](https://github.com/boykopovar/AnyPS5/blob/5b7140766399c64194cc396b5a6c614906c169f6/core/libs/prx/libSceNKWebKit/src/WtfValues.cpp#L679-L683) · [Delegated overload](https://github.com/boykopovar/AnyPS5/blob/5b7140766399c64194cc396b5a6c614906c169f6/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L1404-L1405) ### Non-blocking None. ## Sources Read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, and both changed files: `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp` and `core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp`. Also read the delegated overload in `core/libs/prx/libSceNKWebKit/src/WtfString.cpp`. ## Not verified Tests, builds, and runtime behavior were not run in this review. The description reports tests on Arch Linux with GCC Release, including 187 passing CTest cases and mutation checks; these results were not independently verified. No changed files were excluded from review. ## To get this to a good state Copy the guest URL into a host-side `URL` before calling the `StringView` overload, and add coverage for an unreadable `self` pointer to this overload. Rerun the reported targeted test and CTest checks on the updated head.
MarcZX10 commented 2026-11-23 10:57:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T10:57:26Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: preserve the encoder's updated state when an append fails after growing its buffer.

What I ran

  • Reviewed head 3517150f9390a047060f41a27c0a79765e046f07 using the prepared diff and repo_read.py at that pinned head.
  • No commands or tests were run in this review; reported test results are author-supplied.

Results

Check Result Note
Source review failed One concrete encoder state-loss path
Tests not run Author reports 187/187 passed

Findings

Blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:336: EncoderAppendNum can grow the buffer and replace/free the old one in EncoderEnsure, then return before StoreEncoder if the guest copy-out of the value fails. The guest header still points at the old buffer, which may already have been freed, while the new allocation is leaked. Subsequent use or destruction of that encoder can access a dangling pointer. Store the updated buffer/capacity state as soon as growth succeeds, or otherwise ensure failure leaves the guest header valid and frees any new allocation.

Non-blocking

None.

Not verified

  • Read review/description.md, review/commits.md, review/manifest.json, the relevant ranges of review/diff.patch, WtfValues.cpp, and WtfValueExports.hpp. The manifest lists two changed files and marks both included; the test source was present in the prepared diff, but its full source could not be reliably inspected due to truncated tool output.
  • Did not run the author-reported tests or mutation checks. No console hardware behavior was verified.

To get this to a good state

  • Keep the guest encoder header consistent with buffer ownership when a payload copy-out fails, then rerun the encoder guest-pointer tests and the reported NKWebKit test suite.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:6020429246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6020429246). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T10:57:26Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: preserve the encoder's updated state when an append fails after growing its buffer. ## What I ran - Reviewed head `3517150f9390a047060f41a27c0a79765e046f07` using the prepared diff and `repo_read.py` at that pinned head. - No commands or tests were run in this review; reported test results are author-supplied. ## Results | Check | Result | Note | |---|---|---| | Source review | failed | One concrete encoder state-loss path | | Tests | not run | Author reports 187/187 passed | ## Findings ### Blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:336`: `EncoderAppendNum` can grow the buffer and replace/free the old one in `EncoderEnsure`, then return before `StoreEncoder` if the guest copy-out of the value fails. The guest header still points at the old buffer, which may already have been freed, while the new allocation is leaked. Subsequent use or destruction of that encoder can access a dangling pointer. Store the updated buffer/capacity state as soon as growth succeeds, or otherwise ensure failure leaves the guest header valid and frees any new allocation. ### Non-blocking None. ## Not verified - Read `review/description.md`, `review/commits.md`, `review/manifest.json`, the relevant ranges of `review/diff.patch`, `WtfValues.cpp`, and `WtfValueExports.hpp`. The manifest lists two changed files and marks both included; the test source was present in the prepared diff, but its full source could not be reliably inspected due to truncated tool output. - Did not run the author-reported tests or mutation checks. No console hardware behavior was verified. ## To get this to a good state - Keep the guest encoder header consistent with buffer ownership when a payload copy-out fails, then rerun the encoder guest-pointer tests and the reported NKWebKit test suite.
MarcZX10 commented 2026-11-23 11:24:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T11:24:22Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head bcb24a8dd206987dff56b819b702f2d95ab82b16 using the prepared diff and the pinned repository reader. No commands or tests were run by me; test results below are author-reported.

Results

Check Result Note
Diff and targeted source review passed Both changed files and relevant helper context read
Reported Linux tests not run Author reports 187/187 passed
Added-line review for approval not run Not every added test line was read

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:367 — CopyGuestCString derives its chunk boundary using a fixed 4096-byte modulus. If the host page size differs, a chunk can cross a page boundary and fail on an otherwise valid NUL-terminated string. Query or use the actual host page boundary when choosing each chunk.

Not verified

  • The added test file was not read in full; its 327 added lines are therefore not counted as reviewed. WtfValues.cpp was read in the changed implementation ranges, along with its ABI definitions, relevant helper declarations/implementation, WtfString.cpp protocol behavior, and the test discovery configuration. review/description.md, review/commits.md, review/manifest.json, and review/diff.patch were read; no files were excluded by rule according to the manifest.
  • Tests, mutation checks, convention checks, and progress checks in the description are author-reported and were not run by me. No physical-console behavior was verified.

To get this to a good state

Nothing is required. Optional: calculate CopyGuestCString chunk sizes using the host page size so reads remain within a page across supported hosts.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6020833146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6020833146). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T11:24:22Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Reviewed head `bcb24a8dd206987dff56b819b702f2d95ab82b16` using the prepared diff and the pinned repository reader. No commands or tests were run by me; test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Both changed files and relevant helper context read | | Reported Linux tests | not run | Author reports 187/187 passed | | Added-line review for approval | not run | Not every added test line was read | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:367` — `CopyGuestCString` derives its chunk boundary using a fixed 4096-byte modulus. If the host page size differs, a chunk can cross a page boundary and fail on an otherwise valid NUL-terminated string. Query or use the actual host page boundary when choosing each chunk. ## Not verified - The added test file was not read in full; its 327 added lines are therefore not counted as reviewed. `WtfValues.cpp` was read in the changed implementation ranges, along with its ABI definitions, relevant helper declarations/implementation, `WtfString.cpp` protocol behavior, and the test discovery configuration. `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch` were read; no files were excluded by rule according to the manifest. - Tests, mutation checks, convention checks, and progress checks in the description are author-reported and were not run by me. No physical-console behavior was verified. ## To get this to a good state Nothing is required. Optional: calculate `CopyGuestCString` chunk sizes using the host page size so reads remain within a page across supported hosts.
MarcZX10 commented 2026-11-25 15:30:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T15:30:19Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: make string and C string encoding leave the encoder unchanged when their payload cannot be read.

What I ran

Reviewed head 709b054f579ad9f3f6d8a88d6353109dd8ab7c95 against the prepared diff. No tests or builds were run; the description reports author-run checks.

Results

Check Result Note
Diff and source review passed Two changed files read
Tests and build not run Author-reported results not independently checked

Findings

Blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:674-676: String encoding appends the length and 8-bit flag through separate encoder calls before attempting to copy the payload. If payload GuestCopyIn fails, the function throws after those prefix bytes and their SHA-1 state have already been committed; a retry or subsequent encode therefore operates on a partially encoded value. The CString encoder has the same ordering at lines 684-688. Validate/copy the payload before committing the prefix, or roll back encoder state and bytes when the payload copy fails.

Non-blocking

None.

Not verified

  • Tests, build, and CI were not run. The description reports GCC Release checks and mutation checks, but those results were not independently verified.
  • Only the two changed files were reviewed; excluded files are not listed in the available manifest. No other exclusions were confirmed.

To get this to a good state

  • Make String and CString encoding atomic on payload read failure, then rerun the relevant NKWebKit tests.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:6060531232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6060531232). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T15:30:19Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: make string and C string encoding leave the encoder unchanged when their payload cannot be read. ## What I ran Reviewed head `709b054f579ad9f3f6d8a88d6353109dd8ab7c95` against the prepared diff. No tests or builds were run; the description reports author-run checks. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Two changed files read | | Tests and build | not run | Author-reported results not independently checked | ## Findings ### Blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:674-676`: String encoding appends the length and 8-bit flag through separate encoder calls before attempting to copy the payload. If payload `GuestCopyIn` fails, the function throws after those prefix bytes and their SHA-1 state have already been committed; a retry or subsequent encode therefore operates on a partially encoded value. The CString encoder has the same ordering at lines 684-688. Validate/copy the payload before committing the prefix, or roll back encoder state and bytes when the payload copy fails. ### Non-blocking None. ## Not verified - Tests, build, and CI were not run. The description reports GCC Release checks and mutation checks, but those results were not independently verified. - Only the two changed files were reviewed; excluded files are not listed in the available manifest. No other exclusions were confirmed. ## To get this to a good state - Make String and CString encoding atomic on payload read failure, then rerun the relevant NKWebKit tests.
MarcZX10 commented 2026-11-25 17:22:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:22:56Z.

Review: COMMENTED


Reviewed — comments

The guest pointer handling is substantially covered by new tests, but the Decoder bounds check can perform undefined pointer arithmetic on malformed guest state.

What I ran

Reviewed head 646f74a8a2f707fabc56cecfe98bd3ec705cbea6 using the prepared diff and repo_read.py targeted reads. No tests or build commands were run.

Results

Check Result Note
Diff and targeted source review passed Core changes and new tests inspected
Build and tests not run No local execution

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:353 forms bufferData + bufferSize before establishing that the guest-provided size is within a valid object range. If the size is invalid or the pointer is near the address-space limit, this pointer arithmetic is undefined behavior; the attempted bounds check itself is not safe for malformed state. Consider validating the range using checked integer address arithmetic before forming pointers, and returning false when the range overflows.

Not verified

The build, tests, and author-reported runs were not independently verified. The prepared diff and targeted source reads were reviewed; other repository files listed in manifest.json were not read in full.

To get this to a good state

Nothing is required. Optional: make the DecoderHasRoom range validation safe for malformed pointers and sizes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6061992402 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6061992402). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T17:22:56Z. **Review:** COMMENTED --- # Reviewed — comments The guest pointer handling is substantially covered by new tests, but the `Decoder` bounds check can perform undefined pointer arithmetic on malformed guest state. ## What I ran Reviewed head `646f74a8a2f707fabc56cecfe98bd3ec705cbea6` using the prepared diff and `repo_read.py` targeted reads. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Core changes and new tests inspected | | Build and tests | not run | No local execution | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:353` forms `bufferData + bufferSize` before establishing that the guest-provided size is within a valid object range. If the size is invalid or the pointer is near the address-space limit, this pointer arithmetic is undefined behavior; the attempted bounds check itself is not safe for malformed state. Consider validating the range using checked integer address arithmetic before forming pointers, and returning false when the range overflows. ## Not verified The build, tests, and author-reported runs were not independently verified. The prepared diff and targeted source reads were reviewed; other repository files listed in `manifest.json` were not read in full. ## To get this to a good state Nothing is required. Optional: make the `DecoderHasRoom` range validation safe for malformed pointers and sizes.
MarcZX10 commented 2026-11-25 18:09:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T18:09:41Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: make failed Encoder appends leave both the guest header and buffer state consistent.

What I ran

Reviewed head 2880e0cc618d9757bcf07ee17668fbcb7a6a3bab; no commands or tests were run. Read description.md, commits.md, manifest.json, diff.patch, and the full changed source and test files through the reader. files.json was unavailable, so excluded files and the complete reviewed-file list could not be confirmed.

Results

Check Result Note
Diff and targeted code review passed Source and tests read
Tests not run Only author-reported results available
Excluded-file inventory not run files.json unavailable

Findings

Blocking

  • core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:332 — EncoderWrite copies payload bytes into the guest buffer before updating the host-side SHA-1 and size. If GuestCopyOut_nid_no_patch partially writes and then reports failure, the helper returns false without committing the new size or hash; the guest buffer can nevertheless contain changed bytes within the unused region, violating the claimed unchanged-on-failure behavior and making a retry or subsequent append overwrite those bytes. The tested unreadable cases may fail before copying any bytes, but the implementation does not establish atomicity for a copy-out failure. Stage writes so a failed copy cannot alter the current buffer, or otherwise restore affected bytes before returning.

Non-blocking

None.

Sources

  • Changed encoder write path: core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:331-336.
  • Tests compare encoder state after failed payload reads: core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp:163-168.

Not verified

Tests and build were not run. The author reports test runs in the PR description, but their output was not available here. The files.json inventory was unavailable, so files excluded by preparation rules and whether all reviewed files were read are not verified. No behavior beyond the two changed files read was assessed.

To get this to a good state

Make EncoderWrite failure-safe if guest buffer copy-out can partially modify its destination, then rerun the targeted guest-pointer tests and the reported ctest command on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6062641227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6062641227). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T18:09:41Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: make failed `Encoder` appends leave both the guest header and buffer state consistent. ## What I ran Reviewed head `2880e0cc618d9757bcf07ee17668fbcb7a6a3bab`; no commands or tests were run. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and the full changed source and test files through the reader. `files.json` was unavailable, so excluded files and the complete reviewed-file list could not be confirmed. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Source and tests read | | Tests | not run | Only author-reported results available | | Excluded-file inventory | not run | `files.json` unavailable | ## Findings ### Blocking - `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:332` — `EncoderWrite` copies payload bytes into the guest buffer before updating the host-side SHA-1 and size. If `GuestCopyOut_nid_no_patch` partially writes and then reports failure, the helper returns false without committing the new size or hash; the guest buffer can nevertheless contain changed bytes within the unused region, violating the claimed unchanged-on-failure behavior and making a retry or subsequent append overwrite those bytes. The tested unreadable cases may fail before copying any bytes, but the implementation does not establish atomicity for a copy-out failure. Stage writes so a failed copy cannot alter the current buffer, or otherwise restore affected bytes before returning. ### Non-blocking None. ## Sources - Changed encoder write path: `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp:331-336`. - Tests compare encoder state after failed payload reads: `core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp:163-168`. ## Not verified Tests and build were not run. The author reports test runs in the PR description, but their output was not available here. The `files.json` inventory was unavailable, so files excluded by preparation rules and whether all reviewed files were read are not verified. No behavior beyond the two changed files read was assessed. ## To get this to a good state Make `EncoderWrite` failure-safe if guest buffer copy-out can partially modify its destination, then rerun the targeted guest-pointer tests and the reported `ctest` command on the updated head.
MarcZX10 commented 2026-11-25 18:23:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T18:23:24Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected changes have no verified blocking defect; I did not run the reported checks, so a formal approval is not justified.

What I ran

Reviewed head 2b449290332d9f1a5636fd58ef93fb3d5283cd5d. No commands were run; this session provides the pinned reader but no shell. The description reports Arch Linux/GCC tests and checks; those are author-reported, not runs performed here.

Results

Check Result Note
Source review passed Both changed files read
Reported test suite not run Author-reported only
Mutation checks not run Author-reported only

Negative control

Not run; the reported mutation checks were not independently performed.

Findings

Blocking

None verified.

Non-blocking

None.

Sources

Reviewed core/libs/prx/libSceNKWebKit/src/WtfValues.cpp and core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp from the prepared diff and pinned head.

Not verified

The test suite, mutation checks, convention/progress checks, and console behavior were not independently verified. The prepared bundle lists both changed files as included; files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6062822332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6062822332). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T18:23:24Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected changes have no verified blocking defect; I did not run the reported checks, so a formal approval is not justified. ## What I ran Reviewed head `2b449290332d9f1a5636fd58ef93fb3d5283cd5d`. No commands were run; this session provides the pinned reader but no shell. The description reports Arch Linux/GCC tests and checks; those are author-reported, not runs performed here. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Both changed files read | | Reported test suite | not run | Author-reported only | | Mutation checks | not run | Author-reported only | ## Negative control Not run; the reported mutation checks were not independently performed. ## Findings ### Blocking None verified. ### Non-blocking None. ## Sources Reviewed `core/libs/prx/libSceNKWebKit/src/WtfValues.cpp` and `core/libs/prx/libSceNKWebKit/tests/WtfPersistenceUrlGuestPointers.cpp` from the prepared diff and pinned head. ## Not verified The test suite, mutation checks, convention/progress checks, and console behavior were not independently verified. The prepared bundle lists both changed files as included; `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 14:57:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:57:32Z.

Review: COMMENTED


Built the changed WebKit sources and ran the branch's WtfPersistenceUrlGuestPointers fixture against the existing Linux runtime. It passed, covering the persistence and URL calls changed by this PR.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6172274561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22472#pullrequestreview-6172274561). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T14:57:32Z. **Review:** COMMENTED --- Built the changed WebKit sources and ran the branch's `WtfPersistenceUrlGuestPointers` fixture against the existing Linux runtime. It passed, covering the persistence and URL calls changed by this PR. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/22472:upstream-pr/22472'
git switch 'upstream-pr/22472'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/22472'
git switch 'upstream-pr/22472'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/22472'
git switch 'upstream-pr/22472'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/22472'
git switch 'main'
git merge --squash 'upstream-pr/22472'
git switch 'main'
git merge --ff-only 'upstream-pr/22472'
git switch 'main'
git merge 'upstream-pr/22472'
git push origin 'main'
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!22472
No description provided.