Skip to content

fix(http): safely parse guest response headers - #22415

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
NumberGuan:codex/http-response-header-guest-access
Dec 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
NumberGuan:codex/http-response-header-guest-access

Conversation

@NumberGuan

@NumberGuan NumberGuan commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

sceHttpParseResponseHeader now reads the field name and header through checked guest copies. The parser calculates guest addresses with checked integer offsets and returns a successful value pointer into the original header. It copies the header in blocks and only grows the staging buffer after each successful read. The buffer uses realloc so an allocation failure does not rely on catching a libstdc++ exception on Windows (see #25728). Invalid ranges, failed staging allocations and offsets too large for the return type return INVALID_RESPONSE. The 4095-byte field name limit, folded lines and missing-field outputs keep their existing behavior. Console behavior for invalid memory and allocation failure is unmeasured.

Tested

On Windows, MinGW compiled Export.cpp in syntax-only mode. The complete GuestHttpResponseHeader test passed with the extracted parser linked against the existing guest-copy library. It covers oversized inputs, a header spanning several copy blocks and guard-page cases. A local fault injection probe forced the first allocation and the first resize to fail. Both returned INVALID_RESPONSE and preserved errno and the outputs. Conventions and whitespace checks passed. No full local rebuild, title or PS5 run.

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

@NumberGuan
NumberGuan marked this pull request as ready for review November 17, 2026 14:41
@github-actions

github-actions Bot commented Nov 17, 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 9834 core/libs/prx/libSceHttp/Export.cpp L14

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

@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 — changes requested

Changes are required before merge: avoid unchecked pointer arithmetic and define allocation failure behavior for guest-sized header lengths.

What I ran

Reviewed head e002fe8688ec2cda61752259f0912d778f318b43. I read the prepared description, commits, manifest, diff, all three changed files, and the HttpGuest copy helpers. I did not run commands or tests.

Results

Check Result Note
Diff and changed code passed All changed files read
Tests and build not run Author reports pre-rebase Windows tests only
Console behavior not run Unmapped-memory behavior unmeasured

Findings

Blocking

  • core/libs/prx/libSceHttp/Export.cpp:509 constructs a std::string of headerLen before validating or copying guest memory. A guest-controlled length can request an enormous host allocation, and allocation failure can throw through the exported C API instead of returning a parser error. Bound or safely handle staging allocation so malformed lengths cannot escape as host exceptions.

  • core/libs/prx/libSceHttp/Export.cpp:505 increments fieldStr + fieldLen up to 4095 bytes. For a short valid C string near the end of an addressable object, forming pointers beyond that object is undefined behavior even if the guest-copy helper safely rejects the resulting address. Read the field name using an access method that does not form out-of-object pointers, or establish a safe bounded input contract.

Non-blocking

None.

Not verified

No local build or tests were run. The author reports Windows tests against pre-rebase commit 3d6ad153ef; current-head CI is pending. Linux, title, network and console behavior were not tested. files.json was not available through the reader; manifest lists three changed files, all included, and each was read. No excluded paths were listed in the manifest.

To get this to a good state

Handle guest-controlled allocation size and field-name reads without host exceptions or undefined pointer arithmetic. Then rerun the parser tests and checks on the updated head.

@NumberGuan
NumberGuan force-pushed the codex/http-response-header-guest-access branch from e002fe8 to 1ec2058 Compare November 24, 2026 11:16
@NumberGuan
NumberGuan force-pushed the codex/http-response-header-guest-access branch from 1ec2058 to 8a427ab Compare November 25, 2026 13:00

@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

Nothing blocks this change; the reviewed implementation and test updates support merging, with console behavior still unmeasured.

What I ran

Reviewed head 8a427abfb4a7102f4a4a32197e84fa5709c418da. No commands or tests were run in this review. Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libSceHttp/Export.cpp, core/libs/tests/GuestHttpResponseHeader.cpp, core/libs/prx/libSceHttp/src/GuestAccess.hpp, and docs/dev/debt/changes/http-response-header-guest-access.md. All three changed files listed in the manifest were read; none were excluded.

Results

Check Result Note
Changed code review passed Inspected all changed files
Tests in this review not run No test command run
Console behavior not run Unmeasured per description

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports Windows syntax-only compilation, a parser test run, allocation fault injection, and convention checks; these were not independently run in this review. Full local rebuild and title or PS5 behavior, especially invalid-memory and allocation-failure behavior on console, remain unverified.

To get this to a good state

Nothing is required.

@ligmaSec ligmaSec 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.

The branch's GuestHttpResponseHeader fixture passed when compiled and run on Linux against the existing runtime libraries. It covers the parser's guest output and field validation and verifies the caller's errno in the rejection cases.

AI-assisted: yes.

@Plyxen Plyxen 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.

I read the diff at 8a427abfb4. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at c1593e4e1dd together with other open PRs (so not an isolated build).

  • guest_http_response_header: pass on both.
  • Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to main's): it fails with "HTTP response header check failed".

Not checked: a title.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit 83ee967 into boykopovar:main Dec 4, 2026
14 of 16 checks passed
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