fix(libSceHttp): copy URIs as measured on a PS5 #9073

Merged
orezraey merged 2 commits from upstream-pr/9073 into main 2026-10-23 01:43:44 +00:00
orezraey commented 2026-10-21 11:46:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-21T11:46:31Z.


What

sceHttpUriCopy was written from a reading of the libSceHttp.sprx disassembly, and its debt entry said it was not measured on a console. In a payload process on a PS5 (firmware 13.60) every ordinary input already matched:

  • the field order in the pool (scheme, hostname, path, username, password, each with its terminator);
  • a null field copied as an empty string;
  • the port copied, and the query, fragment and opaque flag left 0;
  • all prepare bytes cleared;
  • require on success, and left alone on a short pool;
  • the error codes for null arguments.

The one difference is the order of operations. The console clears the whole output element and all prepare pool bytes before it reads the source, so a source that is the output itself, or that lies inside the pool, is read after it was cleared:

Case Payload process, firmware 13.60 main before this PR here now
out == src 0, require 5: all five strings empty, port 0 a full copy of the source as on the console
source element stored inside the pool 0, require 5: all five strings empty, port 0 a full copy of the source as on the console
source hostname stored inside the pool the hostname reads as empty (require 0x12, while sizing only counts the real string: 0x1c) the full hostname copied as on the console
fault while clearing the pool (prepare past a guard page) the output was already cleared, so the output is cleared first not determined output first, as on the console

This PR clears out and the pool first, then reads the source pointers and the port, computes the size and copies. A short pool returns ERROR_OUT_OF_MEMORY with both already cleared, as before.

Not measured: whether the console writes the strings before it checks the size. A short pool always ends up cleared, so the order can't be seen. The debt entry says so.

Tests: guest_http checks, inside the existing sceHttpUriCopy block:

  • the pool layout and offsets;
  • the zeroed bytes after require, the padding and the reserved bytes;
  • short and zero-size pools, and the null-argument combinations;
  • opaque 7 and mixed null and empty fields;
  • out == src, and a source element or a source string inside the pool.

The new checks fail on main and pass here.

Debt: the sceHttpUriCopy entry in docs/dev/debt/libSceHttp.md now describes the measured behaviour and the one unmeasured point.

How the console was measured

  • Setup:
    • The console runs firmware 13.60 and is jailbroken.
    • The probes are ELF payloads built with ps5-payload-dev/sdk v0.44 and clang 18.1.8 and started through elfldr, so they ran in a payload process, not in a title.
    • sceHttpInit was not needed and not called.
  • Provenance: libSceHttp.sprx was loaded with dlopen, and sceHttpUriCopy and sceHttpUriParse were taken from it with dlsym.
  • Method:
    • Sources come from sceHttpUriParse and from hand-built elements.
    • Pools are filled with ~, outputs with 0x5a, and require is preset to 0xabcd; every output pointer is logged as an offset into the pool.
    • Each source runs sizing only, with a 256-byte pool, with the exact size and one byte short.
    • uricopy2 and uricopy3 put the pool before a guard page to see the clearing, and alias the source with the output and the pool.
  • Files: the probe sources and full logs are in this gist.
Console output (excerpt, copied unchanged)
uricopy: meta fw=0x13600007 pid=148 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 21 2026 08:18:56 log=/data/anyps5-probes/uricopy.log
uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" exact out opaque=0x00000000 port=8443 scheme=@0"https" user=@23"user" pass=@28"secret" host=@6"example.com"
uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" exact out path=@18"/a/c" query=(null) fragment=(null)
uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" short ret=0x80431022 require=0xabcd
uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" short out opaque=0x00000000 port=0 scheme=(null) user=(null) pass=(null) host=(null)
uricopy2: case out_equals_src ret=0x00000000 require=0x5
uricopy2: case out_equals_src out opaque=0x00000000 port=0 scheme=@0"" user=@3"" pass=@4"" host=@1""
uricopy3: case src_element_inside_pool ret=0x00000000 require=0x5
uricopy3: case src_strings_inside_pool ret=0x00000000 require=0x12
uricopy3: case src_strings_inside_pool out opaque=0x00000000 port=1234 scheme=@0"SCH" user=@10"usr" pass=@14"pwd" host=@4""
uricopy3: case src_strings_inside_pool_size_only ret=0x00000000 require=0x1c
uricopy3: case clear order fault signal=11
uricopy3: case clear_order_after_fault out opaque=0x00000000 port=0 scheme=(null) user=(null) pass=(null) host=(null)

Tested

Windows 11, WinLibs GCC 15.2.0, Release: guest_http, guest_http_response_header and guest_http2 pass. Not tested on Linux or with a title.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951015744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9073). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-21T11:46:31Z. --- ### What `sceHttpUriCopy` was written from a reading of the libSceHttp.sprx disassembly, and its debt entry said it was not measured on a console. In a payload process on a PS5 (firmware 13.60) every ordinary input already matched: - the field order in the pool (scheme, hostname, path, username, password, each with its terminator); - a null field copied as an empty string; - the port copied, and the query, fragment and opaque flag left 0; - all `prepare` bytes cleared; - `require` on success, and left alone on a short pool; - the error codes for null arguments. The one difference is the order of operations. The console clears the whole output element and all `prepare` pool bytes **before** it reads the source, so a source that is the output itself, or that lies inside the pool, is read after it was cleared: | Case | Payload process, firmware 13.60 | `main` before this PR | here now | |---|---|---|---| | `out == src` | 0, `require` 5: all five strings empty, port 0 | a full copy of the source | as on the console | | source element stored inside the pool | 0, `require` 5: all five strings empty, port 0 | a full copy of the source | as on the console | | source hostname stored inside the pool | the hostname reads as empty (`require` 0x12, while sizing only counts the real string: 0x1c) | the full hostname copied | as on the console | | fault while clearing the pool (`prepare` past a guard page) | the output was already cleared, so the output is cleared first | not determined | output first, as on the console | This PR clears `out` and the pool first, then reads the source pointers and the port, computes the size and copies. A short pool returns `ERROR_OUT_OF_MEMORY` with both already cleared, as before. **Not measured:** whether the console writes the strings before it checks the size. A short pool always ends up cleared, so the order can't be seen. The debt entry says so. **Tests:** `guest_http` checks, inside the existing `sceHttpUriCopy` block: - the pool layout and offsets; - the zeroed bytes after `require`, the padding and the reserved bytes; - short and zero-size pools, and the null-argument combinations; - opaque 7 and mixed null and empty fields; - `out == src`, and a source element or a source string inside the pool. The new checks fail on `main` and pass here. **Debt:** the `sceHttpUriCopy` entry in `docs/dev/debt/libSceHttp.md` now describes the measured behaviour and the one unmeasured point. #### How the console was measured - **Setup:** - The console runs firmware 13.60 and is jailbroken. - The probes are ELF payloads built with [ps5-payload-dev/sdk](https://github.com/ps5-payload-dev/sdk) v0.44 and clang 18.1.8 and started through elfldr, so they ran in a payload process, not in a title. - `sceHttpInit` was not needed and not called. - **Provenance:** `libSceHttp.sprx` was loaded with `dlopen`, and `sceHttpUriCopy` and `sceHttpUriParse` were taken from it with `dlsym`. - **Method:** - Sources come from `sceHttpUriParse` and from hand-built elements. - Pools are filled with `~`, outputs with 0x5a, and `require` is preset to 0xabcd; every output pointer is logged as an offset into the pool. - Each source runs sizing only, with a 256-byte pool, with the exact size and one byte short. - `uricopy2` and `uricopy3` put the pool before a guard page to see the clearing, and alias the source with the output and the pool. - **Files:** the probe sources and full logs are in [this gist](https://gist.github.com/orezraey/a7b4d6c93894400bfb2a409dd2d1519b). <details><summary>Console output (excerpt, copied unchanged)</summary> ``` uricopy: meta fw=0x13600007 pid=148 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 21 2026 08:18:56 log=/data/anyps5-probes/uricopy.log uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" exact out opaque=0x00000000 port=8443 scheme=@0"https" user=@23"user" pass=@28"secret" host=@6"example.com" uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" exact out path=@18"/a/c" query=(null) fragment=(null) uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" short ret=0x80431022 require=0xabcd uricopy: case parsed "https://user:[email protected]:8443/a/./b/../c?x=1&y=2#top" short out opaque=0x00000000 port=0 scheme=(null) user=(null) pass=(null) host=(null) uricopy2: case out_equals_src ret=0x00000000 require=0x5 uricopy2: case out_equals_src out opaque=0x00000000 port=0 scheme=@0"" user=@3"" pass=@4"" host=@1"" uricopy3: case src_element_inside_pool ret=0x00000000 require=0x5 uricopy3: case src_strings_inside_pool ret=0x00000000 require=0x12 uricopy3: case src_strings_inside_pool out opaque=0x00000000 port=1234 scheme=@0"SCH" user=@10"usr" pass=@14"pwd" host=@4"" uricopy3: case src_strings_inside_pool_size_only ret=0x00000000 require=0x1c uricopy3: case clear order fault signal=11 uricopy3: case clear_order_after_fault out opaque=0x00000000 port=0 scheme=(null) user=(null) pass=(null) host=(null) ``` </details> ### Tested Windows 11, WinLibs GCC 15.2.0, Release: `guest_http`, `guest_http_response_header` and `guest_http2` pass. Not tested on Linux or with a title. ### 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 (Claude Code)
xXPBSXx commented 2026-10-21 16:14:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:14:35Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_http_tests; ctest -N -R guest_http lists exactly one test.

PR head tested: 19d7e29b3a8bcb215783f4480910fa2601237bd4.

Results (3 runs each):

  • PR head: guest_http passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libSceHttp/src/Uri.cpp with the version from the PR's merge base (3e91c8edf5), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

GPU: the run output has no Selected GPU line; no GPU claim is made.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320721797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9073#issuecomment-6320721797). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T16:14:35Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_http_tests`; `ctest -N -R guest_http` lists exactly one test. **PR head tested:** `19d7e29b3a8bcb215783f4480910fa2601237bd4`. **Results (3 runs each):** - PR head: `guest_http` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libSceHttp/src/Uri.cpp` with the version from the PR's merge base (`3e91c8edf5`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **GPU:** the run output has no `Selected GPU` line; no GPU claim is made. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
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!9073
No description provided.