feat(libSceHttp2): store cookies in cookie boxes #10534

Merged
noamroger merged 2 commits from upstream-pr/10534 into main 2026-10-26 20:25:38 +00:00
noamroger commented 2026-10-24 08:47:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by noamroger on 2026-10-24T08:47:17Z.


What

Gives the cookie boxes sceHttp2CreateCookieBox already creates a real cookie store, in a new Cookies.cpp so it stays out of the transport work in Export.cpp:

  • sceHttp2AddCookie, sceHttp2GetCookie, sceHttp2GetCookieStats, sceHttp2SetCookieMaxNum, sceHttp2SetCookieMaxNumPerDomain and sceHttp2SetCookieMaxSize, with signatures from SharpProspero's Http2.cs, declared in include/Http2.hpp.
  • Behavior follows a run of this PR's test sequence against firmware 13.42's libSceHttp2.sprx (thanks to the reviewer who ran it): error codes, the no-match error, required = header length + 3, no scheme check, refused foreign Domain, cookies without =, prefix/suffix matching, the 4096/50 default limits, oldest-first eviction, a limit of 0, and the 32-byte stats with their size accounting. Expiry keeps the RFC 6265 date algorithm, which matched every tested date.
  • sceHttp2CreateCookieBox maps its pool from flexible memory as 13.42 does and returns the kernel's error unchanged. sceHttp2CookieFlush empties a box and sceHttp2DeleteCookieBox drops its cookies.
  • sceHttp2GetCookieBox/SetCookieBox are untouched (#10167 changes them).

What is still assumed (default total limit, the bytes after the header, the stack check that is not reproduced) is listed in docs/dev/debt/libSceHttp2.md.

Tested

  • Linux x86-64, GCC: GuestHttp2Cookies.cpp (registered as guest_http2_cookies) passes plain and under ASan/UBSan, built by hand against Export.cpp and Cookies.cpp with the kernel's flexible-memory calls stubbed. tools/check_conventions.py --base origin/main passes.
  • Windows 11 (WinLibs GCC 15.2.0, Release): an earlier head (9bcdf99c59) was built and passed 3 of 3 runs by a reviewer; the current head has not been rerun there.
  • Expected values come from the 13.42 run described above; not run on a console by me.

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:4993972602 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10534). Originally posted by [noamroger](https://github.com/noamroger) on 2026-10-24T08:47:17Z. --- ### What Gives the cookie boxes `sceHttp2CreateCookieBox` already creates a real cookie store, in a new `Cookies.cpp` so it stays out of the transport work in `Export.cpp`: - `sceHttp2AddCookie`, `sceHttp2GetCookie`, `sceHttp2GetCookieStats`, `sceHttp2SetCookieMaxNum`, `sceHttp2SetCookieMaxNumPerDomain` and `sceHttp2SetCookieMaxSize`, with signatures from SharpProspero's `Http2.cs`, declared in `include/Http2.hpp`. - Behavior follows a run of this PR's test sequence against firmware 13.42's `libSceHttp2.sprx` (thanks to the reviewer who ran it): error codes, the no-match error, `required` = header length + 3, no scheme check, refused foreign `Domain`, cookies without `=`, prefix/suffix matching, the 4096/50 default limits, oldest-first eviction, a limit of 0, and the 32-byte stats with their size accounting. Expiry keeps the RFC 6265 date algorithm, which matched every tested date. - `sceHttp2CreateCookieBox` maps its pool from flexible memory as 13.42 does and returns the kernel's error unchanged. `sceHttp2CookieFlush` empties a box and `sceHttp2DeleteCookieBox` drops its cookies. - `sceHttp2GetCookieBox`/`SetCookieBox` are untouched (#10167 changes them). What is still assumed (default total limit, the bytes after the header, the stack check that is not reproduced) is listed in `docs/dev/debt/libSceHttp2.md`. ### Tested - Linux x86-64, GCC: `GuestHttp2Cookies.cpp` (registered as `guest_http2_cookies`) passes plain and under ASan/UBSan, built by hand against Export.cpp and Cookies.cpp with the kernel's flexible-memory calls stubbed. `tools/check_conventions.py --base origin/main` passes. - Windows 11 (WinLibs GCC 15.2.0, Release): an earlier head (`9bcdf99c59`) was built and passed 3 of 3 runs by a reviewer; the current head has not been rerun there. - Expected values come from the 13.42 run described above; not run on a console by me. ### 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)
MarcZX10 commented 2026-10-24 11:08:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:08:08Z.

Review: CHANGES_REQUESTED


The oversized-pool guard throws std::overflow_error from this guest-facing extern "C" API. A guest can reach this path with a poolSize above SIZE_MAX - 0x3fff, so the overflow is converted into a C++ exception crossing the ABI boundary (or terminating the process if it is not caught). Please return the project/API error code for an invalid or unrepresentable pool size instead, and add a regression that passes a near-SIZE_MAX value and verifies a normal error return without allocation or exception escape. The ordinary cookie tests and PR checks do not exercise this input.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638024732 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10534#pullrequestreview-5638024732). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:08:08Z. **Review:** CHANGES_REQUESTED --- The oversized-pool guard throws `std::overflow_error` from this guest-facing `extern "C"` API. A guest can reach this path with a `poolSize` above `SIZE_MAX - 0x3fff`, so the overflow is converted into a C++ exception crossing the ABI boundary (or terminating the process if it is not caught). Please return the project/API error code for an invalid or unrepresentable pool size instead, and add a regression that passes a near-`SIZE_MAX` value and verifies a normal error return without allocation or exception escape. The ordinary cookie tests and PR checks do not exercise this input.
MarcZX10 commented 2026-10-24 12:24:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:24:49Z.

Review: DISMISSED


The current head addresses the reported oversized-pool path: rounding overflow and failed array allocation now return the out-of-memory code, and tests cover near-SIZE_MAX inputs. The focused ASan/UBSan run is author-reported; hosted structural checks pass, while product builds are skipped. Please resolve the remaining direct overlap before merge: #10167 changes sceHttp2CookieFlush, sceHttp2CreateCookieBox and sceHttp2DeleteCookieBox in the same Export.cpp, while this PR implements those functions against its cookie store. The current #10167 version makes CookieFlush throw and changes the Create/Delete handle operations, so the behavior cannot be combined by a simple file rebase. Coordinate with its author on an order and the intended composed behavior, then record the dependency/order in this PR. Also coordinate the shared CMake/test relocation with #6044 so GuestHttp2Cookies and its registration are preserved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638227026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10534#pullrequestreview-5638227026). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:24:49Z. **Review:** DISMISSED --- The current head addresses the reported oversized-pool path: rounding overflow and failed array allocation now return the out-of-memory code, and tests cover near-SIZE_MAX inputs. The focused ASan/UBSan run is author-reported; hosted structural checks pass, while product builds are skipped. Please resolve the remaining direct overlap before merge: #10167 changes sceHttp2CookieFlush, sceHttp2CreateCookieBox and sceHttp2DeleteCookieBox in the same Export.cpp, while this PR implements those functions against its cookie store. The current #10167 version makes CookieFlush throw and changes the Create/Delete handle operations, so the behavior cannot be combined by a simple file rebase. Coordinate with its author on an order and the intended composed behavior, then record the dependency/order in this PR. Also coordinate the shared CMake/test relocation with #6044 so GuestHttp2Cookies and its registration are preserved.
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!10534
No description provided.