Skip to content

fix(libSceHttp): read and write sceHttpUriParse and sceHttpUriCopy guest data through guest copies - #20858

Merged
oneandonlydean merged 10 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceHttp-uri-parse-copy-guest
Nov 15, 2026
Merged

oneandonlydean merged 10 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceHttp-uri-parse-copy-guest

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

sceHttpUriParse and sceHttpUriCopy read and wrote guest memory by dereferencing the caller's pointers: the source URL, the source element and its strings, the output element, the pool and the required size. An unmapped pointer faulted the host.

  • sceHttpUriParse: the source URL is read page by page with GuestCopyIn, without a length limit, as the direct string access did. The required size, the pool strings (each with its terminating NUL) and the output element are written with GuestCopyOut, in the same order and with the same bytes as before. An unreadable URL returns ERROR_INVALID_URL, the code the function already returns for a null URL. An unwritable pool, output or required-size pointer returns ERROR_INVALID_VALUE (0x804311FE), the code this library already uses for invalid output values.
  • sceHttpUriCopy: the source element is copied in with GuestCopyIn and each string is read the same way. The output and pool are cleared first, as before, so an output that aliases the source still sees the cleared element, and the existing test that pins that case keeps passing. Unreadable input returns ERROR_INVALID_URL. The output, pool and required size are written with guest copies, with the same order and bytes as before.
  • sceHttpUriBuild, sceHttpUriEscape and sceHttpUriMerge are not changed here (PR fix(libSceHttp): safely probe the outputs of the URI builders #20805 covers their outputs).

Commits: one fix and one test per function, ten in total. The first fix commit compiles on its own; its test target comes with the second commit.

No external source is needed: the change only copies guest memory, and the error codes are the ones these functions already return.

Tested

Host: Linux, kernel 6.1, x86_64. Throwaway archive build of the tree, with the CPU startup gate patched in that build only (no change to HostCpu.cpp in this branch).

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

…pies

sceHttpUriParse measured and copied the source URL with direct string access,
so an unmapped URL faulted the host. The URL is now read page by page with
GuestCopyIn, without a length limit, as the direct access did, and errno is
preserved across each copy. An unreadable URL returns ERROR_INVALID_URL, the
code the same function already returns for a null URL. A readable URL is
parsed from the same bytes as before.
sceHttpUriParse must return ERROR_INVALID_URL and keep errno when the source
URL cannot be read. A readable URL longer than one page must still parse, so
the page-by-page copy is pinned against readable input.
…tCopyOut

sceHttpUriParse stored the required size by writing through the caller's
pointer, so an unmapped output faulted the host. The size is now written
with GuestCopyOut, errno preserved, and an unwritable pointer returns
ERROR_INVALID_VALUE, the code this library returns for an invalid output
value. A writable pointer receives the same value as before.
An unwritable required-size pointer must return ERROR_INVALID_VALUE and keep
errno.
sceHttpUriParse wrote the pool strings and the output element by dereferencing
the caller's pointers, so an unmapped pool or output faulted the host. Each
string is now written with its terminating NUL through GuestCopyOut, in the
same order as before, and the element is written once with GuestCopyOut. Only
the bytes the function wrote before are written, so padding in the pool is
left as it was. An unwritable pool or output returns ERROR_INVALID_VALUE.
An unwritable output element or pool must return ERROR_INVALID_VALUE and keep
errno. A writable call must still fill the element and its hostname.
… copies

sceHttpUriCopy read the source element and its strings by dereferencing the
caller's pointers, so an unmapped source faulted the host. The element is now
copied in with GuestCopyIn and each string is read with the page-by-page
guest copy, without a length limit, as before. The output and pool are cleared
first, as before, so an output that aliases the source still sees the cleared
element. An unreadable source or string returns ERROR_INVALID_URL, the code the
function already returns for a null source. Readable input copies the same
bytes as before.
An unreadable source element must return ERROR_INVALID_URL and keep errno. A
readable source must copy its hostname and port, and an unreadable string
inside a readable source must also return ERROR_INVALID_URL.
sceHttpUriCopy cleared the output and pool, wrote the strings and the output
element, and stored the required size, all by dereferencing the caller's
pointers, so an unmapped output or pool faulted the host. The output and pool
are cleared first, in the same order as before, with a 256-byte zero copy for
the pool and a guest copy for the element. Each string is then written with its
terminating NUL through GuestCopyOut, and the element and the required size are
written with GuestCopyOut. The bytes written are the same as before. An
unwritable output, pool or required-size pointer returns ERROR_INVALID_VALUE.
Unwritable output, pool or required-size pointers must return ERROR_INVALID_VALUE
and keep errno. A size-only call must still report the required size of the
readable source: the hostname and four empty fields, each with its terminator,
16 bytes.
@MarcZX10
MarcZX10 force-pushed the fix/libsceHttp-uri-parse-copy-guest branch from be89ded to 0892125 Compare November 15, 2026 17:46
@oneandonlydean
oneandonlydean merged commit c209471 into boykopovar:main Nov 15, 2026
14 checks passed
oneandonlydean added a commit that referenced this pull request Nov 16, 2026
#21158)

This reverts #20858 (merge c209471). Since it merged, guest_http
aborts on Linux on every run (main alone in batch pb-20261115T1917Z and
three local runs on d4a1472); with #20858 reverted it passes.
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@MarcZX10 after this merged, the Linux guest_http test started aborting on main (subprocess abort in the full ctest run, on every Linux run since), so I reverted it in #21158 to get main green. The change itself still looks right to me. If you open a new PR with the same change and guest_http passing on Linux, it can land again.

oneandonlydean pushed a commit that referenced this pull request Nov 17, 2026
… copies

This reverts 3c9ddc9 (#21158), which reverted #20858 because
guest_http aborted on Linux on every run. The cause, found on #21158, is
the padding of the SceHttpUriElement the two calls build on the host
stack and write to the guest whole; the next commit zeroes it.

Co-authored-by: MarcZX10 <67475268+MarcZX10@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants