feat(libSceNKWebKit): implement WTF::URLParser::allValuesEqual and internalValuesConsistent #15867

Merged
KernelPanicNT merged 1 commit from upstream-pr/15867 into main 2026-11-09 19:34:05 +00:00
KernelPanicNT commented 2026-11-04 20:29:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-11-04T20:29:15Z.


What

Implements two libSceNKWebKit exports that called NotImplemented_nid_no_patch: WTF::URLParser::allValuesEqual(URL const&, URL const&) (MlSHagwBWI4) and WTF::URLParser::internalValuesConsistent(URL const&) (jKPJKar5yGY). Both are static, return bool and follow WebKit's URLParser.cpp. They use the 40-byte WTF::URL model the tree already has: String m_string at 0, then the bitfield word at 8, then the seven unsigned offsets.

  • allValuesEqual compares the two strings the way String == String does: the same StringImpl or two null impls are equal, a null impl and an empty one are not, and otherwise length and code units are compared, so 8-bit and 16-bit copies of the same text are equal. Then it compares every field. m_isValid, m_protocolIsInHTTPFamily, m_cannotBeABaseURL, m_portLength and m_schemeEnd fill the 32-bit bitfield word exactly (1+1+1+3+26 bits), so comparing the whole word compares all five, whatever the bit order. The seven offsets are then compared one by one. The URL_PARSER_LOG call has no effect, because URL_PARSER_DEBUGGING is 0.
  • internalValuesConsistent checks the order schemeEnd <= userStart <= userEnd <= passwordEnd <= hostEnd, then hostEnd + portLength <= pathAfterLastSlash <= pathEnd <= queryEnd <= length. The scheme end comes from bits 6-31 and the port length from bits 3-5, as URL::protocol, URL::path and URL::isHierarchical already decode them. The sum is unsigned, so it wraps modulo 2^32 as in WebKit, where the 3-bit field becomes int and is then converted to unsigned. A null string has length 0.
  • A null URL reference throws std::invalid_argument through the same Checked helper as equalIgnoringFragmentIdentifier and the other URL exports. A StringImpl with a null character pointer and a nonzero length throws in the existing Unit helper. These are the cases where WebKit dereferences invalid memory.

WTF::URLParser::maybeCanonicalizeScheme is left out. The module export is _ZN3WTF9URLParser23maybeCanonicalizeSchemeERKNS_6StringE, which takes String const&. The cited WebKit revision declares std::optional<String> maybeCanonicalizeScheme(StringView) instead, so its body is not the source of this export and its return ABI is not established. It still throws.

One new debt entry records that the two functions were not compared with a console module. The two NID rows leave the list of throwing inventory exports. The 7429 of the 8703 sentence keeps its historical value, as the file header says inventory prose does.

Source of the behaviour

No device measurement was made for this change. The behaviour is the cited WebKit source.

Open PRs: none implement these exports. #14303 (protocolHostAndPortAreEqual) adds code at the same place in WtfString.cpp. #13992 changes the lines next to these stubs in Export.cpp and InventoryExports.hpp. #14858 adds tests at the same place in tests/Wtf.cpp, and #14918, #14919 and #14920 change its includes. Each of these conflicts is textual only. tools/pr_overlap.py also lists #13486 under the same exports, but that PR only changes relinker files; its branch is behind main.

Tested

Linux (GitHub Codespace, GCC 14), on main 9ab6a281ea. nkwebkit_wtf passes with the new TestURLParserChecks, and the change builds without warnings. The test checks:

  • allValuesEqual:
    • It is true for the same object, for a separate 8-bit copy of the string and for a 16-bit copy, in both argument orders.
    • It is false when the text differs by one character or by length.
    • It is false when any single bit changes (valid, HTTP family, cannot-be-a-base, the low and high port-length bits, the low and top scheme-end bits) and when any of the seven offsets changes.
    • Two null strings are equal; a null string and an empty one are not.
  • internalValuesConsistent:
    • It is true for a consistent https URL with user, password, port, path, query and fragment, and for the all-zero URL.
    • For each of the eight inequalities, it is false one past the bound and true at the bound. This includes the port length, which turns hostEnd + 4 = pathAfterLastSlash false and hostEnd + 5 true.
    • A queryEnd past a null string is false.
    • The flag bits are ignored.
    • hostEnd = 0xFFFFFFFF with port length 1 wraps to 0 and passes; with port length 2 it fails.
  • Null references throw for both exports. A corrupt StringImpl with a null character pointer throws when two such strings are compared, and is equal to itself.

Negative control, two runs of the same test: with the bits comparison in allValuesEqual and the port length in internalValuesConsistent removed, the library builds and nkwebkit_wtf aborts on a failed check; with Export.cpp, InventoryExports.hpp, WtfExports.hpp and WtfString.cpp from main, the test no longer compiles (too many arguments to function), because the two exports are again argument-less NotImplemented_nid_no_patch stubs. tools/progress.py: +2 implemented functions (libSceNKWebKit 1309/11248 -> 1311/11248). tools/check_conventions.py passes.

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5161124555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15867). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-04T20:29:15Z. --- ### What Implements two `libSceNKWebKit` exports that called `NotImplemented_nid_no_patch`: `WTF::URLParser::allValuesEqual(URL const&, URL const&)` (`MlSHagwBWI4`) and `WTF::URLParser::internalValuesConsistent(URL const&)` (`jKPJKar5yGY`). Both are static, return `bool` and follow WebKit's `URLParser.cpp`. They use the 40-byte `WTF::URL` model the tree already has: `String m_string` at 0, then the bitfield word at 8, then the seven `unsigned` offsets. - `allValuesEqual` compares the two strings the way `String == String` does: the same `StringImpl` or two null impls are equal, a null impl and an empty one are not, and otherwise length and code units are compared, so 8-bit and 16-bit copies of the same text are equal. Then it compares every field. `m_isValid`, `m_protocolIsInHTTPFamily`, `m_cannotBeABaseURL`, `m_portLength` and `m_schemeEnd` fill the 32-bit bitfield word exactly (1+1+1+3+26 bits), so comparing the whole word compares all five, whatever the bit order. The seven offsets are then compared one by one. The `URL_PARSER_LOG` call has no effect, because `URL_PARSER_DEBUGGING` is 0. - `internalValuesConsistent` checks the order `schemeEnd <= userStart <= userEnd <= passwordEnd <= hostEnd`, then `hostEnd + portLength <= pathAfterLastSlash <= pathEnd <= queryEnd <= length`. The scheme end comes from bits 6-31 and the port length from bits 3-5, as `URL::protocol`, `URL::path` and `URL::isHierarchical` already decode them. The sum is unsigned, so it wraps modulo 2^32 as in WebKit, where the 3-bit field becomes `int` and is then converted to `unsigned`. A null string has length 0. - A null `URL` reference throws `std::invalid_argument` through the same `Checked` helper as `equalIgnoringFragmentIdentifier` and the other `URL` exports. A `StringImpl` with a null character pointer and a nonzero length throws in the existing `Unit` helper. These are the cases where WebKit dereferences invalid memory. `WTF::URLParser::maybeCanonicalizeScheme` is left out. The module export is `_ZN3WTF9URLParser23maybeCanonicalizeSchemeERKNS_6StringE`, which takes `String const&`. The cited WebKit revision declares `std::optional<String> maybeCanonicalizeScheme(StringView)` instead, so its body is not the source of this export and its return ABI is not established. It still throws. One new debt entry records that the two functions were not compared with a console module. The two NID rows leave the list of throwing inventory exports. The `7429 of the 8703` sentence keeps its historical value, as the file header says inventory prose does. **Source of the behaviour** No device measurement was made for this change. The behaviour is the cited WebKit source. - `allValuesEqual` and `internalValuesConsistent`: [`URLParser.cpp#L2976-L3031`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/URLParser.cpp#L2976-L3031). Declarations: [`URLParser.h#L56-L57`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/URLParser.h#L56-L57). Disabled logging: [`URLParser.cpp#L36-L42`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/URLParser.cpp#L36-L42). - URL fields and bitfields: [`URL.h#L229-L247`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/URL.h#L229-L247). - String equality and length: [`WTFString.h#L324`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/text/WTFString.h#L324), [`WTFString.h#L104`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/text/WTFString.h#L104), [`StringImpl.cpp#L1393-L1396`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/text/StringImpl.cpp#L1393-L1396) and [`StringCommon.h#L321-L338`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/text/StringCommon.h#L321-L338). - `maybeCanonicalizeScheme` signature at that revision: [`URLParser.h#L65`](https://github.com/WebKit/WebKit/blob/3539f609da3d/Source/WTF/wtf/URLParser.h#L65). - Revision range: the two cited functions have the same text in every `URLParser.cpp` revision from `c124b4197109` (January 2020) to `3539f609da3d`. The next change to the file, `638ac8184b38`, renames `m_cannotBeABaseURL` to `m_hasOpaquePath`. The `URL.h` member block has the same text from `e762431f808c` (December 2019) to `3539f609da3d`, and it also changes next in `638ac8184b38`. At `3539f609da3d`, `URL.h`, `URL.cpp` and `URLParser.h` are byte-identical to the WebKit text the existing NKWebKit debt entries cite as their pinned source. `URLParser.cpp` differs from that text only by one line moved at L1211-L1212, outside the cited range, so the cited line numbers are the same. - Previous behaviour: [`Export.cpp#L20235-L20245`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/Export.cpp#L20235-L20245), [`InventoryExports.hpp#L2031-L2033`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp#L2031-L2033), and names and NIDs at [`libSceNKWebKit.md#L1975-L1977`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/docs/dev/debt/libSceNKWebKit.md#L1975-L1977). `maybeCanonicalizeScheme` stays at [`Export.cpp#L12323`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/Export.cpp#L12323). - URL model and bit decoding reused: [`WtfStringAbi.hpp#L23-L44`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp#L23-L44), [`WtfString.cpp#L880-L884`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L880-L884) (port length), [`#L975-L978`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L975-L978) (scheme end), and the helpers `Checked`, `View` and `EqualImpls` at [`#L208-L220`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L208-L220) and [`#L308-L311`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L308-L311). The null-reference throw follows [`equalIgnoringFragmentIdentifier`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L957-L961). Open PRs: none implement these exports. #14303 (`protocolHostAndPortAreEqual`) adds code at the same place in `WtfString.cpp`. #13992 changes the lines next to these stubs in `Export.cpp` and `InventoryExports.hpp`. #14858 adds tests at the same place in `tests/Wtf.cpp`, and #14918, #14919 and #14920 change its includes. Each of these conflicts is textual only. `tools/pr_overlap.py` also lists #13486 under the same exports, but that PR only changes relinker files; its branch is behind `main`. ### 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. --> Linux (GitHub Codespace, GCC 14), on `main` `9ab6a281ea`. `nkwebkit_wtf` passes with the new `TestURLParserChecks`, and the change builds without warnings. The test checks: - `allValuesEqual`: - It is true for the same object, for a separate 8-bit copy of the string and for a 16-bit copy, in both argument orders. - It is false when the text differs by one character or by length. - It is false when any single bit changes (valid, HTTP family, cannot-be-a-base, the low and high port-length bits, the low and top scheme-end bits) and when any of the seven offsets changes. - Two null strings are equal; a null string and an empty one are not. - `internalValuesConsistent`: - It is true for a consistent `https` URL with user, password, port, path, query and fragment, and for the all-zero URL. - For each of the eight inequalities, it is false one past the bound and true at the bound. This includes the port length, which turns `hostEnd + 4 = pathAfterLastSlash` false and `hostEnd + 5` true. - A `queryEnd` past a null string is false. - The flag bits are ignored. - `hostEnd = 0xFFFFFFFF` with port length 1 wraps to 0 and passes; with port length 2 it fails. - Null references throw for both exports. A corrupt `StringImpl` with a null character pointer throws when two such strings are compared, and is equal to itself. Negative control, two runs of the same test: with the `bits` comparison in `allValuesEqual` and the port length in `internalValuesConsistent` removed, the library builds and `nkwebkit_wtf` aborts on a failed check; with `Export.cpp`, `InventoryExports.hpp`, `WtfExports.hpp` and `WtfString.cpp` from `main`, the test no longer compiles (`too many arguments to function`), because the two exports are again argument-less `NotImplemented_nid_no_patch` stubs. `tools/progress.py`: +2 implemented functions (libSceNKWebKit 1309/11248 -> 1311/11248). `tools/check_conventions.py` passes. ### 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) - [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
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!15867
No description provided.