Skip to content

fix(libSceHttp): copy parsed header outputs through guest memory - #26082

Closed
malekaifa wants to merge 5 commits into
boykopovar:mainfrom
malekaifa:prime-f/fix-http-response-header-guest-pointers-20261123
Closed

malekaifa wants to merge 5 commits into
boykopovar:mainfrom
malekaifa:prime-f/fix-http-response-header-guest-pointers-20261123

Conversation

@malekaifa

@malekaifa malekaifa commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Route sceHttpParseResponseHeader output stores through the libSceHttp guest-memory helpers instead of writing guest pointers directly. Both the empty-field and normal-value paths now return SCE_HTTP_ERROR_INVALID_VALUE for unwritable guest output pointers.

Add regression coverage for unmapped fieldValue and valueLen destinations on both non-empty and empty response-header values. The latest test-only follow-up adds the missing empty-value bad-valueLen case identified by independent mutation testing; production code is unchanged from the previously reviewed implementation.

Overlap: #22415 independently implements the same two output stores and also adds guest-safe input copies. The branches conflict in core/libs/prx/libSceHttp/Export.cpp. This PR does not depend on #22415; maintainers should choose one implementation or reconcile whichever lands second.

Tested

Windows 11 / MSYS2 UCRT64 GCC 16.2 / Ninja on implementation head e189bfeceea5:

  • built guest_http_response_header_tests;
  • guest_http_response_header: 1/1 passed;
  • tools/check_conventions.py: passed;
  • git diff --check: clean;
  • negative control with Export.cpp reverted to main fails on the unsafe direct stores.

Independent Windows / WinLibs GCC 15.2 validation merged the implementation onto newer main, ran guest_http_response_header plus seven neighbouring HTTP/HTTP2 tests 3/3, and exercised six mutations. The only surviving mutation was the empty-value direct valueLen store; the one-line assertion now present on head b2a02ea65de6 was separately demonstrated to pass on the merge and fail under that mutation.

Fresh hosted CI is running on b2a02ea65de6.

Checklist

  • Based on current main; semantic overlap with fix(http): safely parse guest response headers #22415 is disclosed above
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt / licence notices
  • Unimplemented paths still throw; this change only hardens guest output stores
  • No notes, investigation files or images added
  • No new third-party code
  • Generic guest-memory behavior, not title-specific
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Copilot AI balanced review requested due to automatic review settings November 23, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@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 e189bfecee:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_http_response_header_tests built cleanly.
  • CTest (guest_http_response_header):
    1/1 Test #4049: guest_http_response_header .......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceHttp/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4049: guest_http_response_header .......***Exception: SegFault  0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified HttpGuest::Store usage in Export.cpp correctly handles unwritable guest memory destinations for both fieldValue and valueLen across empty and non-empty header value paths.
    • Verified return error code invalidValue (0x804321FE) matches the expected SCE_HTTP_ERROR_INVALID_VALUE for bad output pointer destinations.
    • Verified null pointer checks for header, fieldStr, fieldValue, and valueLen remain intact and execute before any guest memory access.
    • Verified 64-bit LP64/LLP64 portability and type safety with std::size_t and const char* writes via HttpGuest::Store.
    • Verified AGENTS.md compliance: no disallowed comments introduced, no title-specific hacks, clean conventional commit title, and regression tests added in GuestHttpResponseHeader.cpp.

Looks Good To Me

@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 — comments

The reviewed diff has no verified blocking finding, but review completeness is limited to the supplied change summary and patch.

What I ran

No commands were run. The reader and repository source files were not available through the tools in this session.

Results

Check Result Note
Diff review not run Inputs could not be read
Tests not run No test commands run

Findings

Blocking

None verified.

Non-blocking

No code-level feedback could be verified.

Not verified

The description, commits, manifest, diff, changed-file contents, and repository callers were not read. Changed and excluded file lists are therefore not verified.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the prx label Nov 23, 2026
@malekaifa

Copy link
Copy Markdown
Contributor Author

Merge-ready handoff at exact head e189bfeceea56e36182e00554c56f7592c5a12cb: Windows, conventions, intake, labels, eligibility, report, and library-portability are green. PrivacyOnion independently built and passed the focused HTTP response-header test on Linux and its negative control reproduces the unsafe main behavior. The PR remains MERGEABLE/CLEAN with no verified blocking review finding. Maintainer merge requested.

AI-assisted: yes

@malekaifa

Copy link
Copy Markdown
Contributor Author

Merge-ready handoff at exact head e189bfeceea56e36182e00554c56f7592c5a12cb: Build, progress-report, and Emscripten portability workflows are completed/successful, and the PR is mergeable. PrivacyOnion independently built and passed guest_http_response_header 1/1 on Linux and reproduced the negative control by reverting the implementation fix; MarcZX10 reported no verified blocking finding and nothing is required. The change is limited to guest-safe parsed-header output stores plus their regression coverage, and the body retains AI-assisted: yes. Maintainer merge requested.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 22415 core/libs/prx/libSceHttp/Export.cpp L525-528, L557-559

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/prx/libSceHttp/Export.cpp
PR 11134 core/libs/prx/libSceHttp/Export.cpp

@Helldiverr

Copy link
Copy Markdown
Contributor

Works on native Windows with a second toolchain, and 5 of 6 mutations of the new stores are caught; one survives, and #22415 makes the same two stores and conflicts with this PR.

guest_http_response_header plus 7 neighbouring HTTP and HTTP/2 tests: 8/8 on each of 3 runs of the merge, and 8/8 on main. Negative control: fails. Mutations: 5 of 6 caught, and a one-line check catches the sixth. check_conventions and debt_fold --check pass.

Existing runs:

  • The description reports a Windows 11 run with MSYS2 UCRT64 GCC 16.2 of the new test, plus check_conventions.
  • PrivacyOnion approved e189bfecee after a Linux run (Ubuntu 24.04, GCC 13.3) of the new test. In PrivacyOnion's negative control, the test crashes with a SegFault when Export.cpp is reverted to main.
  • MarcZX10 commented without running anything, and Copilot did not review.

What this run adds.

  • A second Windows toolchain, WinLibs GCC 15.2, with 7 neighbouring tests on main and on the merge. Three of them (guest_http2_gzip_members, guest_http2_gzip_headers, guest_http2_transport) cover libSceHttp2, which calls sceHttpParseResponseHeader with host stack outputs (core/libs/prx/libSceHttp2/Transport.cpp:102).
  • A sweep of 6 mutations, and a check that catches the one that survives.
  • A check of what is written when one store fails.
  • A merge check against fix(http): safely parse guest response headers #22415.

Code.

  • Both output paths now store through HttpGuest::Store (core/libs/prx/libSceHttp/Export.cpp:528 for an empty value, :560 otherwise), which is GuestCopyOut_nid_no_patch (core/libs/prx/libSceHttp/src/GuestAccess.hpp:15-18). A failed store returns invalidValue (0x804321FE).
  • The rest of the diff follows the rules: no code comments, no title-specific branches, no third-party sources.
  • When fieldValue is writable and valueLen is not, *fieldValue is written before the function returns invalidValue. I checked this on the merge by replacing the reset at core/libs/tests/GuestHttpResponseHeader.cpp:108-109 with a print: after the call at :106, value points at "yes" instead of marker, and the check at :114 then fails. The reset hides this rather than pinning it. Whether a console leaves *fieldValue alone here is not measured, so either pin the current order in the test or write neither output on failure.
  • The function still reads header and fieldStr in place (Export.cpp:502-503). docs/dev/debt/libSceHttp.md:7 says it "still read or write guest buffers in place". After this PR that is true only of the reads, so a debt fragment could narrow the line.
  • Overlap: fix(http): safely parse guest response headers #22415 (NumberGuan, "fix(http): safely parse guest response headers", head e002fe8688, opened 2026-11-17) also routes both output stores through HttpGuest::Store, and also copies header and fieldStr in through HttpGuest::CopyIn. It has an open change request from MarcZX10 about the input copies, not the stores. git merge-tree of this merge (4600b5f629) with fix(http): safely parse guest response headers #22415 reports a content conflict in core/libs/prx/libSceHttp/Export.cpp. The pr-overlap bot comment lists fix(http): safely parse guest response headers #22415 too, but the description's checklist says "no open PR implements the same fix". The maintainers will need to pick one or sequence them.

Negative control and mutation.

  • Negative control: in the merge, I reverted Export.cpp to main and kept the new test lines. The test crashes with a SegFault, as in PrivacyOnion's Linux run.
  • Mutations, one at a time, each against the PR's test:
# Change PR's test
M1 empty value: *valueLen = length instead of HttpGuest::Store (Export.cpp:528) passes
M2 empty value: *fieldValue = value instead of HttpGuest::Store (:528) fails (SegFault)
M3 empty value: a failed store returns 0 (:528) fails (exit 0xc0000409)
M4 other values: *valueLen = length instead of HttpGuest::Store (:560) fails (SegFault)
M5 other values: *fieldValue = value instead of HttpGuest::Store (:560) fails (SegFault)
M6 other values: a failed store returns end (:560) fails (exit 0xc0000409)
  • M1 survives because the empty-value path is tested only with a bad fieldValue (GuestHttpResponseHeader.cpp:107). Adding the matching line:
    Require(sceHttpParseResponseHeader("X:", 2, "X", &value, reinterpret_cast<std::size_t*>(0x10)) == invalidValue);
    after :107 passes on the merge and crashes with a SegFault under M1.

Tests.

Run Commit response_header guest_pointers uri_guest_pointers chunks options http2_gzip_members http2_gzip_headers http2_transport
main 1e3005814c pass (old test) pass pass pass pass pass pass pass
merge 1 4600b5f629 pass pass pass pass pass pass pass pass
merge 2 4600b5f629 pass pass pass pass pass pass pass pass
merge 3 4600b5f629 pass pass pass pass pass pass pass pass
negative control merge with main's Export.cpp fails (SegFault) n/a n/a n/a n/a n/a n/a n/a
M1 merge with one mutation passes n/a n/a n/a n/a n/a n/a n/a
M2 to M6 merge with one mutation fails n/a n/a n/a n/a n/a n/a n/a
extra check merge, and merge with M1 passes on the merge; fails under M1 n/a n/a n/a n/a n/a n/a n/a

The column names drop the guest_http_ prefix and, for the HTTP/2 tests, guest_.

Command: ctest --test-dir build -R '^(guest_http_response_header|guest_http_guest_pointers|guest_http_uri_guest_pointers|guest_http_chunks|guest_http_options|guest_http2_gzip_members|guest_http2_gzip_headers|guest_http2_transport)$' -V. On the merge, py -3 tools/check_conventions.py --base 1e3005814c reports "All conventions checks passed." and py -3 tools/debt_fold.py --check exits 0.

Host

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head e189bfecee, merged onto main 1e3005814c as 4600b5f629

AI-assisted: yes

@malekaifa

Copy link
Copy Markdown
Contributor Author

@Helldiverr Thanks — I added the missing empty-value bad-valueLen assertion on current head b2a02ea65de6b3a636a593d93decac87db2ddc9a, matching the one-line check from your mutation run, so M1 is now pinned. I also corrected the PR description/checklist to disclose that #22415 implements the same two output stores and conflicts in Export.cpp. Production code is unchanged in this follow-up; fresh hosted CI is running. AI-assisted: yes

@Helldiverr

Copy link
Copy Markdown
Contributor

Thanks, @malekaifa. I re-ran on Windows at b2a02ea65d, merged onto current main 47d328f1c4 as 0da592126f.

  • guest_http_response_header passes 3 of 3 times.
  • With M1 applied, the test now fails with a SegFault at the new check (GuestHttpResponseHeader.cpp:108). M1 is the direct *valueLen write on the empty-value path.

So all 6 mutations are now caught.

Two points from my review are still open. Neither blocks the PR:

  • When the valueLen store fails, *fieldValue has already been written. The reset after the failing call still hides this.
  • docs/dev/debt/libSceHttp.md:7 still describes in-place writes, but they are now only in-place reads.

AI-assisted: yes

@Helldiverr

Copy link
Copy Markdown
Contributor

Thanks for narrowing the debt entry. The fragment still does not fold at 82c8a7652a:

$ py -3 tools/debt_fold.py --check
docs/dev/debt/changes/fix-libSceHttp-parse-response-header-guest-memory.md:3: 'sceHttpGetCookie' matches 2 entries of libSceHttp, not one

At 4e85bf8c36 it failed the same way, with sceHttpParseResponseHeader matching 2 entries; that name also appears in the signature entry at docs/dev/debt/libSceHttp.md:27. Aps5HttpClient_Read occurs only in the guest-buffer entry at line 7. With ## change Aps5HttpClient_Read as the heading and the text unchanged, debt_fold.py --check exits 0 here (Windows, checked at 4e85bf8c36, which has the same entry text).

AI-assisted: yes

@Helldiverr

Helldiverr commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Confirmed at 3865422470: py -3 tools/debt_fold.py --check exits 0 on Windows, and the fragment now changes only the guest-buffer entry, so the debt point from my review is addressed. The other non-blocking point, that *fieldValue is already written when the valueLen store fails, is unchanged.

AI-assisted: yes

@malekaifa

Copy link
Copy Markdown
Contributor Author

@Helldiverr Follow-up on your remaining debt note: current head 3865422470b17251ffbd839980f86b13e0b525df narrows the Functional debt entry so sceHttpParseResponseHeader is documented as reading its guest header in place while fieldValue/valueLen now use checked guest copies. No runtime/test source changed after b2a02ea65d. On exact head 3865422470b1, tools/debt_fold.py --check, tools/check_conventions.py, and git diff --check origin/main...HEAD all pass. The partial-output ordering note remains intentionally unchanged because console atomicity is unmeasured. AI-assisted: yes

@github-actions github-actions Bot added the docs label Nov 23, 2026
@malekaifa

Copy link
Copy Markdown
Contributor Author

Closing this narrower PR to avoid competing implementations of the same sceHttpParseResponseHeader output stores already owned by #22415. The current branch and its validation evidence are preserved: the guest-safe output-store regression, mutation coverage, negative control, and debt-fold fixes remain useful corroboration. #22415 is the canonical implementation path even though its broader input-staging changes still have review work to resolve. I will not open another parallel implementation of these same stores. AI-assisted: yes

@malekaifa malekaifa closed this Nov 23, 2026
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.

5 participants