feat(libSceNKWebKit): implement WebCore::isValidContentType #16853

Merged
AlexWhitehouse merged 2 commits from upstream-pr/16853 into main 2026-11-11 14:26:06 +00:00
AlexWhitehouse commented 2026-11-07 18:24:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T18:24:31Z.


What

libSceNKWebKit WebCore::isValidContentType(const WTF::String&, Mode) (_ZN7WebCore18isValidContentTypeERKN3WTF6StringENS_4ModeE, NID ewE3P6Jh1n4) threw not implemented. This PR implements it from the PS5 WebKit tree the other NKWebKit ports use, 80f77e94: ParsedContentType.cpp and ParsedContentType.h. There, the export returns whether ParsedContentType::create(contentType, mode) succeeds.

  • ABI: the argument is the guest's one-pointer WTF::String, read as 8-bit or UTF-16 through the same StringImpl flags the other NKWebKit exports use. Mode is a 32-bit enum (Rfc2045 = 0, MimeSniff = 1), and the result is a bool. No ParsedContentType, map or vector crosses the boundary.
  • Parser: this ports parseContentType with its quirks, rather than a standards-based validator:
    • MimeSniff trims HTTP whitespace first and checks type and subtype as RFC 7230 tokens.
    • Rfc2045 rejects CR/LF anywhere, stops tokens at the first non-token character (so trailing text after a valid subtype is accepted), and requires = and a value for every parameter.
    • parseQuotedString reads characters into a char, so it truncates them, and steps one past the closing quote. As a result, a="x";b=y is rejected in Rfc2045 mode while a="x";;b=y is accepted.
    • The MimeSniff quoted-string collector and the empty-value continue follow the source.
  • Empty input: a null or empty string returns false, as create does for an empty string. A non-empty string with null character storage throws std::invalid_argument, where upstream would dereference null, matching the other NKWebKit string consumers.
  • Placement: the new source starts with ParsedContentType.cpp's notice. WebCore::Mode and the export are declared in WebCoreParsersExports.hpp beside the other WebCore parser exports. The stub is removed from Export.cpp, InventoryExports.hpp and the inventory table, the NKWebKit count drops from 6000 to 5999 on current main, and a debt entry records that the console ABI and behaviour are unverified.

Tested

  • New test: nkwebkit_contenttypevalidation makes 224 checks. It runs each of 53 strings in both modes, as both 8-bit and UTF-16 WTF::Strings (212 checks), plus 4 UTF-16-only strings with characters above 0xFF, which cover the char truncation (8), a null String in both modes (2), and a non-empty String with null character storage in both modes, which must throw std::invalid_argument (2). The strings cover:
    • empty, whitespace-only and null input;
    • a missing type, slash or subtype;
    • forbidden characters;
    • parameters with and without values;
    • empty, unterminated and escaped quoted strings, and text after a closing quote;
    • CR/LF in every position;
    • an embedded NUL;
    • non-ASCII characters.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, all 222 string calls throw _ZN7WebCore18isValidContentTypeERKN3WTF6StringENS_4ModeE not implemented (measured before the null-storage checks were added);
    • with this PR at 779d7acdcd, all 224 checks pass.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): nkwebkit_contenttypevalidation passed at e05ab3f35c, before the rebases and the header move, as did the neighbouring nkwebkit_httpheaderfield, nkwebkit_httpheadermap, nkwebkit_mimetyperegistry, nkwebkit_webcoreparsers and nkwebkit_wtftext (6/6), with no compiler warnings in the changed files. The windows CI job builds the current head.
  • Mutation checks: swapping the Rfc2045 and MimeSniff branches fails 102 of the 222 string checks, including text/plain; in both widths. Throwing a not implemented std::runtime_error for null storage instead of std::invalid_argument fails both null-storage checks.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py --branch feat/libscenkwebkit-is-valid-content-type: no open PR implements isValidContentType or ParsedContentType.
    • #16386 adds a debt entry at the same insertion point, and #16316 edits the count line.
    • 74 NKWebKit PRs conflict with main, so the tool couldn't compare them. I read each one's diff by hand: none changes this export, its NID or the new files. Those that touch Export.cpp, InventoryExports.hpp or the count line need only a recount when one merges, as do my #16642 and #16643.
    • #15260 implements WebCore::ContentType, a different class.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5204610648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16853). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T18:24:31Z. --- ### What libSceNKWebKit `WebCore::isValidContentType(const WTF::String&, Mode)` (`_ZN7WebCore18isValidContentTypeERKN3WTF6StringENS_4ModeE`, NID `ewE3P6Jh1n4`) threw `not implemented`. This PR implements it from the PS5 WebKit tree the other NKWebKit ports use, 80f77e94: [`ParsedContentType.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/ParsedContentType.cpp) and [`ParsedContentType.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/ParsedContentType.h). There, the export returns whether `ParsedContentType::create(contentType, mode)` succeeds. - **ABI:** the argument is the guest's one-pointer `WTF::String`, read as 8-bit or UTF-16 through the same `StringImpl` flags the other NKWebKit exports use. `Mode` is a 32-bit enum (`Rfc2045 = 0`, `MimeSniff = 1`), and the result is a `bool`. No `ParsedContentType`, map or vector crosses the boundary. - **Parser:** this ports `parseContentType` with its quirks, rather than a standards-based validator: - `MimeSniff` trims HTTP whitespace first and checks type and subtype as RFC 7230 tokens. - `Rfc2045` rejects CR/LF anywhere, stops tokens at the first non-token character (so trailing text after a valid subtype is accepted), and requires `=` and a value for every parameter. - `parseQuotedString` reads characters into a `char`, so it truncates them, and steps one past the closing quote. As a result, `a="x";b=y` is rejected in `Rfc2045` mode while `a="x";;b=y` is accepted. - The `MimeSniff` quoted-string collector and the empty-value `continue` follow the source. - **Empty input:** a null or empty string returns `false`, as `create` does for an empty string. A non-empty string with null character storage throws `std::invalid_argument`, where upstream would dereference null, matching the other NKWebKit string consumers. - **Placement:** the new source starts with `ParsedContentType.cpp`'s notice. `WebCore::Mode` and the export are declared in `WebCoreParsersExports.hpp` beside the other WebCore parser exports. The stub is removed from `Export.cpp`, `InventoryExports.hpp` and the inventory table, the NKWebKit count drops from 6000 to 5999 on current `main`, and a debt entry records that the console ABI and behaviour are unverified. ### Tested - **New test:** `nkwebkit_contenttypevalidation` makes 224 checks. It runs each of 53 strings in both modes, as both 8-bit and UTF-16 `WTF::String`s (212 checks), plus 4 UTF-16-only strings with characters above 0xFF, which cover the `char` truncation (8), a null `String` in both modes (2), and a non-empty `String` with null character storage in both modes, which must throw `std::invalid_argument` (2). The strings cover: - empty, whitespace-only and null input; - a missing type, slash or subtype; - forbidden characters; - parameters with and without values; - empty, unterminated and escaped quoted strings, and text after a closing quote; - CR/LF in every position; - an embedded NUL; - non-ASCII characters. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, all 222 string calls throw `_ZN7WebCore18isValidContentTypeERKN3WTF6StringENS_4ModeE not implemented` (measured before the null-storage checks were added); - with this PR at 779d7acdcd, all 224 checks pass. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): `nkwebkit_contenttypevalidation` passed at e05ab3f35c, before the rebases and the header move, as did the neighbouring `nkwebkit_httpheaderfield`, `nkwebkit_httpheadermap`, `nkwebkit_mimetyperegistry`, `nkwebkit_webcoreparsers` and `nkwebkit_wtftext` (6/6), with no compiler warnings in the changed files. The `windows` CI job builds the current head. - **Mutation checks:** swapping the `Rfc2045` and `MimeSniff` branches fails 102 of the 222 string checks, including `text/plain;` in both widths. Throwing a `not implemented` `std::runtime_error` for null storage instead of `std::invalid_argument` fails both null-storage checks. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py --branch feat/libscenkwebkit-is-valid-content-type`:** no open PR implements `isValidContentType` or `ParsedContentType`. - #16386 adds a debt entry at the same insertion point, and #16316 edits the count line. - 74 NKWebKit PRs conflict with `main`, so the tool couldn't compare them. I read each one's diff by hand: none changes this export, its NID or the new files. Those that touch `Export.cpp`, `InventoryExports.hpp` or the count line need only a recount when one merges, as do my #16642 and #16643. - #15260 implements `WebCore::ContentType`, a different class. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-07 22:15:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T22:15:45Z.

Review: COMMENTED


Read 6269107aae against main.

I compared Parse with parseContentType, parseToken, parseQuotedString and collectHTTPQuotedString at 80f77e94 and found no divergence. That includes the char truncation in the RFC 2045 quoted string, the extra advance after the closing quote, and the empty-after-trim subtype, which upstream's substring returns as a non-null empty view. The index && bound on the trailing-whitespace loop is equivalent, because the character before the token is always / or =. isHTTPSpace and the RFC 7230 token set match HTTPParsers.h and RFC7230.cpp.

Two optional notes:

  • Null storage. ContentTypeValidation.cpp:150 reports a non-empty string with null data as not implemented, although the export is implemented and the input is invalid. The sibling ports (#16901, #16890) throw std::invalid_argument for the same case.
  • Header placement. The WebCore Mode enum and the export sit in WtfExports.hpp; the other WebCore parser exports and their enums live in WebCoreParsersExports.hpp under namespace WebCore.

The body still says 6373 to 6372 and cites e05ab3f35c for the Windows run. The diff correctly does 6368 to 6367, and the source, test and header files are identical at e05ab3f35c and the head, so the run still applies.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815249600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16853#pullrequestreview-5815249600). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T22:15:45Z. **Review:** COMMENTED --- Read `6269107aae` against `main`. I compared `Parse` with `parseContentType`, `parseToken`, `parseQuotedString` and `collectHTTPQuotedString` at `80f77e94` and found no divergence. That includes the `char` truncation in the RFC 2045 quoted string, the extra advance after the closing quote, and the empty-after-trim subtype, which upstream's `substring` returns as a non-null empty view. The `index &&` bound on the trailing-whitespace loop is equivalent, because the character before the token is always `/` or `=`. `isHTTPSpace` and the RFC 7230 token set match HTTPParsers.h and RFC7230.cpp. Two optional notes: - **Null storage.** `ContentTypeValidation.cpp:150` reports a non-empty string with null data as `not implemented`, although the export is implemented and the input is invalid. The sibling ports (#16901, #16890) throw `std::invalid_argument` for the same case. - **Header placement.** The WebCore `Mode` enum and the export sit in `WtfExports.hpp`; the other WebCore parser exports and their enums live in `WebCoreParsersExports.hpp` under `namespace WebCore`. The body still says 6373 to 6372 and cites `e05ab3f35c` for the Windows run. The diff correctly does 6368 to 6367, and the source, test and header files are identical at `e05ab3f35c` and the head, so the run still applies. Not run here; this is from reading the code. 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!16853
No description provided.