Skip to content

fix(libSceHttp): copy sceHttpUriUnescape's input and outputs through guest copies - #21591

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/http-uri-unescape-guest-copies
Nov 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/http-uri-unescape-guest-copies

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

sceHttpUriUnescape read its input in place, through a std::string_view that measured it with strlen. It also wrote the decoded bytes into out one at a time and stored *requiredSize directly. So an unreadable input, or an unwritable out or requiredSize, crashed the host. The other URI helpers in Uri.cpp already go through the file's CopyGuestCString and WriteGuestBytes, as sceHttpUriMerge does.

Now:

  • The input is copied with CopyGuestCString, in page-bounded chunks, and both validation passes run on the copy.
  • The decoded bytes are built locally and written with one WriteGuestBytes, and requiredSize is written the same way. errno is kept.
  • An unreadable input, or an unwritable output, returns ERROR_INVALID_VALUE (0x804311FE), the result this export already gives for a null input.

What stays the same:

  • The ERROR_INVALID_URL checks and their order: malformed % sequences first, then the pre-1.0 SDK character set.
  • A short out still returns ERROR_OUT_OF_MEMORY with exactly capacity decoded bytes written and no terminator, as the old per-byte loop left it. The existing guest_http cases pin this.
  • requiredSize is written only on success.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON:

  • guest_http gains three cases:
    • an unmapped (0x10) input returns 0x804311FE, and leaves out and requiredSize unchanged;
    • an unmapped out returns 0x804311FE and leaves requiredSize unchanged;
    • an unmapped requiredSize returns 0x804311FE after out received "a b".
  • guest_http passes, 3 runs of 3, including the existing unescape table and the short-buffer cases. Rerun after rebasing onto main 3ebf5692c0 (head ad11e93604): still 3 of 3, and the negative control below still fails the same way.
  • Negative control: with main's Uri.cpp and the new cases, guest_http ends in fatal SIGSEGV (code 1) at address 0x0000000000000010.
  • tools/check_conventions.py passes on the branch and this body.
  • maskym's Windows run of ad11e93604 merged into main 56c87adbdc (Windows 11, i7-12700K, WinLibs GCC 15.2.0, Release): guest_http, guest_http_uri_locale, pass 2/2, three runs.
  • ycbuzi's full ctest runs of ad11e93604 merged into main on GitHub-hosted Windows Server 2022 and 2025 runners (WinLibs GCC 15.2.0): nothing fails that doesn't also fail on main on the same runner.

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 (fix(libSceHttp): restore the sceHttpUriParse and sceHttpUriCopy guest copies with the element padding zeroed #22501, which restored CopyGuestCString and WriteGuestBytes, is merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The change copies guest input and routes output writes through guest memory helpers; I found no verified blocking defect in the changed code.

What I ran

Reviewed head 0c7558005ed49253e320e882bdea135ae24aa2a7 against main. No commands or tests were run; I inspected the prepared diff, the changed lines, and the relevant helper implementations with repo_read.py.

Files read: core/libs/prx/libSceHttp/src/Uri.cpp (lines 70–155 and 280–390) and core/libs/tests/GuestHttp.cpp (lines 580–670). Both changed files listed in the manifest were read. No changed files were excluded.

Results

Check Result Note
Diff and changed lines passed Both changed files inspected
Targeted source review passed Guest copy helpers and unescape path inspected
Tests not run Author reports guest_http passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported test runs, negative control, and convention check were not independently run. Runtime behavior outside the inspected paths was not verified.

To get this to a good state

Nothing is required.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0c7558005e:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_http_tests built cleanly.
  • CTest (guest_http, guest_http_uri_locale):
    1/2 Test #3615: guest_http_uri_locale ............   Passed    0.08 sec
    2/2 Test #3614: guest_http .......................   Passed    0.38 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceHttp/src/Uri.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #3615: guest_http_uri_locale ............   Passed    0.04 sec
    2/2 Test #3614: guest_http .......................***Exception: SegFault  1.70 sec
    50% tests passed, 1 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libSceHttp/src/Uri.cpp: sceHttpUriUnescape checks !input || (!out && !requiredSize) first, then calls CopyGuestCString(input, copied) which reads in page-bounded chunks and preserves errno, returning ERROR_INVALID_VALUE on unreadable guest memory.
    • Verified core/libs/prx/libSceHttp/src/Uri.cpp: Both % hex-sequence validation and pre-1.0 SDK character set validation run unchanged against source (copied) before any writes to out or requiredSize.
    • Verified core/libs/prx/libSceHttp/src/Uri.cpp: When out is non-null and unescaped.size() >= capacity, up to capacity decoded bytes (without a null terminator) are written via WriteGuestBytes when capacity != 0, returning ERROR_INVALID_VALUE if the write faults and ERROR_OUT_OF_MEMORY otherwise without modifying requiredSize.
    • Verified core/libs/prx/libSceHttp/src/Uri.cpp: On sufficient capacity, unescaped.size() + 1 bytes including the null terminator are written via WriteGuestBytes(out, ...), followed by writing size (unescaped.size() + 1) to requiredSize via WriteGuestBytes(requiredSize, &size, sizeof(size)), returning ERROR_INVALID_VALUE if either write fails.
    • Verified core/libs/tests/GuestHttp.cpp: Added test cases cover unmapped (0x10) input, out, and requiredSize pointers in sceHttpUriUnescape and verify the return code (ERROR_INVALID_VALUE) and partial/unmodified output state.

Looks Good To Me

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9834 core/libs/tests/GuestHttp.cpp
PR 11134 core/libs/tests/GuestHttp.cpp

@milescoviello

Copy link
Copy Markdown
Contributor Author

This branch is based on main from before #21158 reverted #20858, and it uses the CopyGuestCString and WriteGuestBytes helpers #20858 added to Uri.cpp. They aren't on current main, so on its own this won't build there, even though GitHub shows it as mergeable. #22501 restores them, so I've set Depends on: #22501. The two diffs apply together cleanly.

@NumberGuan NumberGuan mentioned this pull request Nov 17, 2026
12 tasks done
@malekaifa

Copy link
Copy Markdown
Contributor

On current main 3ebf5692c06c6baa37f7a0602d5a05835143bf25, I confirmed CopyGuestCString and WriteGuestBytes are present in core/libs/prx/libSceHttp/src/Uri.cpp (blob 06c5a9e16051c65229fca6aa03e23231d3d6a789); PR #22501 is merged, so the stated dependency is resolved. The current sceHttpUriUnescape implementation on main still uses std::string_view source(input) and direct out[written] / *requiredSize writes, so the regression remains relevant.

I manually compared the GuestHttp.cpp hunks behind the overlap-bot warning: PRs #9834 and #11134 modify lines 481–490, 707–724 and 809+, while this PR adds the unescape cases at lines 613–615. Those hunks do not overlap. Both PRs remain open, so the bot inability to compare their merge-conflicted branches remains recorded; this manual file-level comparison found no same-line collision.

Current PR head 0c7558005ed49253e320e882bdea135ae24aa2a7 is 1504 commits behind current main; it needs a rebase and fresh checks before merge. I will not open a competing PR.

…guest copies

sceHttpUriUnescape read its input in place and wrote the decoded bytes and
the required size straight through the caller's pointers. The input is now
copied with CopyGuestCString and the result written with WriteGuestBytes;
a bad pointer returns ERROR_INVALID_VALUE, and a short output still gets
exactly capacity bytes with ERROR_OUT_OF_MEMORY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello
milescoviello force-pushed the fix/http-uri-unescape-guest-copies branch from 0c75580 to ad11e93 Compare November 18, 2026 03:30
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks for checking. I rebased the branch onto main 3ebf5692c0; the new head is ad11e93604, the same single commit. guest_http passes 3 of 3 there. With main's Uri.cpp and the new cases, it still ends in fatal SIGSEGV (code 1) at address 0x0000000000000010. I've changed the body's Depends-on line to none, since #22501 is in.

@malekaifa

Copy link
Copy Markdown
Contributor

@boykopovar — this PR is approved by MarcZX10 and PrivacyOnion, all applicable required checks pass, and GitHub reports it CLEAN/MERGEABLE. The reviewed implementation/test file blobs are unchanged at the current head. The submitting account cannot execute MergePullRequest; could a maintainer merge when convenient?

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head ad11e93604, merged alone into main 56c87adbdc (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. Microsoft Defender on this machine quarantines 34 AGC test executables as Trojan:Win64/ShellCode.MKA!MTB when they are linked (the case docs/dev/BUILD.md describes), so their objcopy step fails on both trees and those tests do not run here. This PR adds no other build failure.

The tests this PR adds or extends, guest_http, guest_http_uri_locale, pass 2/2, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@ycbuzi

ycbuzi commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Tested ad11e93604 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 3 tests failed out of 6204; 99% tests passed, 3 tests failed out of 6204. 3 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6204; 100% tests passed, 0 tests failed out of 6204. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @maskym for the Windows run. I've added it to the Tested section, linked to your comment.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @ycbuzi for the full-suite Windows runs. I've added them to the Tested section, linked to your report.

@malekaifa

Copy link
Copy Markdown
Contributor

Rechecked against current upstream main 332d495633e2 on 2026-11-19. The PR remains CLEAN/MERGEABLE; its current diff is limited to Uri.cpp and GuestHttp.cpp, and the sceHttpUriUnescape change still addresses the direct guest input/output accesses present on main. The exact head ad11e93604d58ec4569588301504681c005483e7 has approvals from MarcZX10 and PrivacyOnion, and the Windows build, portability, progress report, conventions and labels checks pass. I don't have MergePullRequest permission on this repository, so a maintainer merge is needed; no code changes appear necessary from this recheck.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @malekaifa for rechecking this against current main 332d495633.

@oneandonlydean
oneandonlydean merged commit 780fe84 into boykopovar:main Nov 19, 2026
16 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants