fix(libSceHttp): safely probe the outputs of the URI builders #20805

Open
Tanju42 wants to merge 2 commits from upstream-pr/20805 into main
Tanju42 commented 2026-11-15 15:49:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tanju42 on 2026-11-15T15:49:16Z.


What

sceHttpUriBuild, sceHttpUriEscape and sceHttpUriMerge wrote requiredSize/require through direct stores and the output buffer through raw std::memcpy — an unmapped guest output was a raw host write. Route every one of these writes through GuestCopyOut_nid_no_patch, in the order the library already wrote them; an unwritable output returns SCE_HTTP_ERROR_INVALID_VALUE (0x804311FE) and leaves errno alone, following sceHttpsGetSslError in the same library. The merge's non-opaque path keeps #12056's zero-padded copy of the relative URI, including the forced terminator at the last byte. Console behavior on unwritable outputs is unmeasured; recorded as a docs/dev/debt/changes fragment.

Tested

Ubuntu 24.04 cloud VM, 8 cores, CPU-only (lavapipe), no GPU. Fresh full build tree (configure + 5500+ targets) of this stack: full ctest green and -R guest_http green. No game titles run. core/libs/tests/GuestHttp.cpp gains Require lines for sceHttpUriBuild, sceHttpUriEscape and sceHttpUriMerge: unmapped output or require pointers return SCE_HTTP_ERROR_INVALID_VALUE with errno preserved, and a valid call right after a failed one still succeeds. python3 tools/check_conventions.py --base origin/main clean. pr_overlap.py --branch output verbatim below.

Independent Windows verification by a contributor: head 0306eb9a23 merged alone into main 56c87adbdc on Windows 11 26300 (i7-12700K, WinLibs GCC 15.2.0, Release) — the tests this PR adds/extends, guest_http and guest_http_uri_locale, pass 2/2 over three runs, and the PR adds no build failure beyond main's own UploadCacheReadOnlyFlush.cpp setenv break (fixed by #19899) and the Defender AGC-test quarantine case documented in BUILD.md. Not run on a PS5. Full report.

Checklist

  • Based on current main; no other open PR implements the same functions — sits on #12056's head 3b10a94b24 (main 228cd64b53); no open PR touches the six sceHttpUri* exports
  • 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 new stubs
  • No notes, investigation .md files or images added to the repository (attach them to this PR) — only the mandated debt fragment under docs/dev/debt/changes/
  • New third-party code is a submodule built from source — none
  • Generic behaviour, not specific to one title
  • Depends on: #12056
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no GPU code)
  • AI-assisted: yes

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
docs/dev/debt/libSceHttp.md
PR 11134 core/libs/tests/GuestHttp.cpp
docs/dev/debt/libSceHttp.md
PR 14212 docs/dev/debt/libSceHttp.md
PR 18515 docs/dev/debt/libSceHttp.md
PR 19769 docs/dev/debt/libSceHttp.md

Manual comparison of that list: #9834 and #11134 edit core/libs/tests/GuestHttp.cpp only in their transport/CA areas — neither diff line touches the URI or escape tests (git diff origin/main...pr9834 -- core/libs/tests/GuestHttp.cpp contains no URI/escape lines); #14212 is itself a debt-file formatting PR; #18515 and #19769 share only docs/dev/debt/libSceHttp.md entry lines — #19769's GuestCopy pass covers scalar and struct outputs and does not overlap any sceHttpUri* export.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5324398712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20805). Originally posted by [Tanju42](https://github.com/Tanju42) on 2026-11-15T15:49:16Z. --- ### What `sceHttpUriBuild`, `sceHttpUriEscape` and `sceHttpUriMerge` wrote `requiredSize`/`require` through direct stores and the output buffer through raw `std::memcpy` — an unmapped guest output was a raw host write. Route every one of these writes through `GuestCopyOut_nid_no_patch`, in the order the library already wrote them; an unwritable output returns `SCE_HTTP_ERROR_INVALID_VALUE` (`0x804311FE`) and leaves `errno` alone, following `sceHttpsGetSslError` in the same library. The merge's non-opaque path keeps #12056's zero-padded copy of the relative URI, including the forced terminator at the last byte. Console behavior on unwritable outputs is unmeasured; recorded as a `docs/dev/debt/changes` fragment. ### Tested Ubuntu 24.04 cloud VM, 8 cores, CPU-only (lavapipe), no GPU. Fresh full build tree (configure + 5500+ targets) of this stack: full `ctest` green and `-R guest_http` green. No game titles run. `core/libs/tests/GuestHttp.cpp` gains `Require` lines for `sceHttpUriBuild`, `sceHttpUriEscape` and `sceHttpUriMerge`: unmapped output or `require` pointers return `SCE_HTTP_ERROR_INVALID_VALUE` with `errno` preserved, and a valid call right after a failed one still succeeds. `python3 tools/check_conventions.py --base origin/main` clean. `pr_overlap.py --branch` output verbatim below. Independent Windows verification by a contributor: head `0306eb9a23` merged alone into `main` `56c87adbdc` on Windows 11 26300 (i7-12700K, WinLibs GCC 15.2.0, Release) — the tests this PR adds/extends, `guest_http` and `guest_http_uri_locale`, pass 2/2 over three runs, and the PR adds no build failure beyond `main`'s own `UploadCacheReadOnlyFlush.cpp` `setenv` break (fixed by #19899) and the Defender AGC-test quarantine case documented in `BUILD.md`. Not run on a PS5. [Full report](https://github.com/boykopovar/AnyPS5/pull/20805#issuecomment-6975371593). ### 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 — sits on #12056's head `3b10a94b24` (main `228cd64b53`); no open PR touches the six `sceHttpUri*` exports - [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 — no new stubs - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) — only the mandated debt fragment under `docs/dev/debt/changes/` - [x] New third-party code is a submodule built from source — none - [x] Generic behaviour, not specific to one title - [x] Depends on: #12056 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (no GPU code) - [x] AI-assisted: yes <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/9834) | `core/libs/tests/GuestHttp.cpp`<br>`docs/dev/debt/libSceHttp.md` | | [PR 11134](https://www.github.com/boykopovar/AnyPS5/pull/11134) | `core/libs/tests/GuestHttp.cpp`<br>`docs/dev/debt/libSceHttp.md` | | [PR 14212](https://www.github.com/boykopovar/AnyPS5/pull/14212) | `docs/dev/debt/libSceHttp.md` | | [PR 18515](https://www.github.com/boykopovar/AnyPS5/pull/18515) | `docs/dev/debt/libSceHttp.md` | | [PR 19769](https://www.github.com/boykopovar/AnyPS5/pull/19769) | `docs/dev/debt/libSceHttp.md` | Manual comparison of that list: #9834 and #11134 edit `core/libs/tests/GuestHttp.cpp` only in their transport/CA areas — neither diff line touches the URI or escape tests (`git diff origin/main...pr9834 -- core/libs/tests/GuestHttp.cpp` contains no URI/escape lines); #14212 is itself a debt-file formatting PR; #18515 and #19769 share only `docs/dev/debt/libSceHttp.md` entry lines — #19769's GuestCopy pass covers scalar and struct outputs and does not overlap any `sceHttpUri*` export.
MarcZX10 commented 2026-11-22 07:53:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:53:05Z.

Review: COMMENTED


Reviewed — no blocking findings

The change routes the URI builder outputs through guest-safe copies and preserves the documented short-buffer behavior; no blocking defect was verified.

What I ran

Reviewed head 0306eb9a23407d4a80e21dbbe04cc34fb693323f. I read the prepared description, commits, manifest, diff, and all four changed files. I inspected the touched helpers and the GuestCopyOut_nid_no_patch implementation with repo_read.py. No commands or tests were run.

Results

Check Result Note
Diff and changed files passed All four changed files read
Tests and build not run No test execution performed
Negative control not run No assertion was deliberately broken

Findings

Blocking

None.

Non-blocking

None.

Sources

The review covered Uri.cpp at the reviewed head, GuestHttp.cpp at the reviewed head, and General.cpp at the reviewed head.

Not verified

Builds, tests, and runtime behavior were not independently verified. The review bundle included full text for every changed file; no changed files were excluded.

To get this to a good state

Nothing is required. Tests and build were not run in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011122162 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20805#pullrequestreview-6011122162). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T07:53:05Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change routes the URI builder outputs through guest-safe copies and preserves the documented short-buffer behavior; no blocking defect was verified. ## What I ran Reviewed head `0306eb9a23407d4a80e21dbbe04cc34fb693323f`. I read the prepared description, commits, manifest, diff, and all four changed files. I inspected the touched helpers and the `GuestCopyOut_nid_no_patch` implementation with `repo_read.py`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All four changed files read | | Tests and build | not run | No test execution performed | | Negative control | not run | No assertion was deliberately broken | ## Findings ### Blocking None. ### Non-blocking None. ## Sources The review covered [Uri.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/0306eb9a23407d4a80e21dbbe04cc34fb693323f/core/libs/prx/libSceHttp/src/Uri.cpp), [GuestHttp.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/0306eb9a23407d4a80e21dbbe04cc34fb693323f/core/libs/tests/GuestHttp.cpp), and [General.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/0306eb9a23407d4a80e21dbbe04cc34fb693323f/core/libs/prx/libc/src/General.cpp). ## Not verified Builds, tests, and runtime behavior were not independently verified. The review bundle included full text for every changed file; no changed files were excluded. ## To get this to a good state Nothing is required. Tests and build were not run in this review.
malekaifa commented 2026-11-23 03:12:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T03:12:06Z.

Review: CHANGES_REQUESTED


@Tanju42 current head 0306eb9a23407d4a80e21dbbe04cc34fb693323f is still stacked on #12056 and preserves its unresolved short-buffer %XX behavior in ProbeTextRaw(value, out, prepare). Firmware 13.42 evidence and @oneandonlydean's Nov. 1 request show that a short sceHttpUriEscape buffer must stop before a %XX unit that would cross the end (a b, prepare 2 => a, not a%). Please let #12056 fix that measured boundary, then restack this PR and retain the guest-pointer safety changes/tests on the corrected behavior. My earlier debt-link conventions objection remains retracted; this is the remaining blocker. AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016153874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20805#pullrequestreview-6016153874). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-11-23T03:12:06Z. **Review:** CHANGES_REQUESTED --- @Tanju42 current head `0306eb9a23407d4a80e21dbbe04cc34fb693323f` is still stacked on #12056 and preserves its unresolved short-buffer `%XX` behavior in `ProbeTextRaw(value, out, prepare)`. Firmware 13.42 evidence and @oneandonlydean's Nov. 1 request show that a short `sceHttpUriEscape` buffer must stop before a `%XX` unit that would cross the end (`a b`, prepare 2 => `a`, not `a%`). Please let #12056 fix that measured boundary, then restack this PR and retain the guest-pointer safety changes/tests on the corrected behavior. My earlier debt-link conventions objection remains retracted; this is the remaining blocker. AI-assisted: yes
malekaifa commented 2026-11-23 15:37:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T15:37:17Z.

Review: APPROVED


Superseding my earlier change request: the conventions-link concern was retracted after reproducing the repository checker, and I have now validated this exact head against current main.

Reviewed exact PR head 0306eb9a23407d4a80e21dbbe04cc34fb693323f. I merged it in an isolated worktree onto current main c3aec4c2f341247e2ed47ae9365e2eff8e880c75. The merge is conflict-free even though main has since added broader guest-input probing in Uri.cpp and GuestHttp.cpp; the merged source retains both that newer input safety and this PR's ProbeText/ProbeSize output safety.

Machine main, Windows 11, MSYS2 UCRT64 GCC 16.2.0, Release: current-main + this PR built guest_http_tests, and ctest -R ^guest_http$ --output-on-failure passed 1/1. The merged tree also passes current conventions and git diff --check.

No blocking findings remain from my review.

AI-assisted review: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6024501092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20805#pullrequestreview-6024501092). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-11-23T15:37:17Z. **Review:** APPROVED --- Superseding my earlier change request: the conventions-link concern was retracted after reproducing the repository checker, and I have now validated this exact head against current `main`. Reviewed exact PR head `0306eb9a23407d4a80e21dbbe04cc34fb693323f`. I merged it in an isolated worktree onto current main `c3aec4c2f341247e2ed47ae9365e2eff8e880c75`. The merge is conflict-free even though main has since added broader guest-input probing in `Uri.cpp` and `GuestHttp.cpp`; the merged source retains both that newer input safety and this PR's `ProbeText`/`ProbeSize` output safety. Machine `main`, Windows 11, MSYS2 UCRT64 GCC 16.2.0, Release: current-main + this PR built `guest_http_tests`, and `ctest -R ^guest_http$ --output-on-failure` passed 1/1. The merged tree also passes current conventions and `git diff --check`. No blocking findings remain from my review. AI-assisted review: yes
ligmaSec commented 2026-12-03 15:23:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:23:29Z.

Review: COMMENTED


I ran guest_http and guest_http_uri_guest_pointers with the patch applied on Linux. Both passed, covering the URI builders' valid results and guarded output destinations.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6172783687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20805#pullrequestreview-6172783687). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T15:23:29Z. **Review:** COMMENTED --- I ran `guest_http` and `guest_http_uri_guest_pointers` with the patch applied on Linux. Both passed, covering the URI builders' valid results and guarded output destinations. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/20805:upstream-pr/20805'
git switch 'upstream-pr/20805'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/20805'
git switch 'upstream-pr/20805'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/20805'
git switch 'upstream-pr/20805'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/20805'
git switch 'main'
git merge --squash 'upstream-pr/20805'
git switch 'main'
git merge --ff-only 'upstream-pr/20805'
git switch 'main'
git merge 'upstream-pr/20805'
git push origin 'main'
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!20805
No description provided.