fix(libSceHttp): bound response header values as a PS5 does #5476

Closed
hugodearaujo wants to merge 1 commit from upstream-pr/5476 into main
hugodearaujo commented 2026-10-13 20:46:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-13T20:46:48Z.


What

sceHttpParseResponseHeader disagreed with a PS5 (firmware 13.60) in three ways, measured through the console's libSceHttp.sprx from a payload:

  1. An empty value returned the next header line. For Empty:\r\nSpaces: v \r\n…, main returned Spaces: v as the value of Empty; the leading-whitespace skip consumed the line break. The console returns 0 with a null value and length 0, and does not look for a later field of the same name (E2:\r\nE2: second is empty too).
  2. The return value counted the line break. The console returns the offset of the value's end (value - header + length), for example 23 for Content-Type: text/html\r\n…; main returned 25.
  3. The value's end differs in a few line-break cases. A value that runs to the end of the buffer keeps its final line break (X: right\n gives right\n, X: abc\r\n\tdef\r\n gives abc\r\n\tdef\r\n), and a bare line feed after the colon is skipped as whitespace (X:\nY: z gives Y: z), while the line feed of a CRLF is not (X:\r\nY: z is empty).

The new code follows a model fitted to the console and then checked on data it had not seen:

  • every combination of up to 4 of {space, tab, CR, LF, v} after X:, alone and followed by Y: z (1,562 headers);
  • every combination of 5 of {space, CR, LF, v} (2,048);
  • every combination of 5 of {space, tab, CR, LF, v} (6,250);
  • the 20 inputs of the existing guest_http_response_header test and 16 mixed headers.

The model matches all of them. It skips leading whitespace up to the line feed of a CRLF. It then ends the value at the first line feed followed by a character other than space or tab, without its carriage return when that line feed, or the value's first one, ends a CRLF; with no such line feed, at the end of the buffer.

The existing test expectations came from shadPS4 and encoded the old results (X:\r\nnext\r\n gave next); they now hold the console's results.

Tested

  • PS5 (firmware 13.60): about 9,900 headers through the console's sceHttpParseResponseHeader, compared with this implementation (no mismatch).
  • Linux: full CTest 1070/1071. guest_http_response_header fails with this PR's Export.cpp reverted and passes with it. agc_driver_tessellation segfaults the same way on main.
  • Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: CTest 1097 tests with no failures (the GPU tests skip in this VM).
  • No title I have calls this function, so this is console evidence only.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849266648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5476). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-13T20:46:48Z. --- ### What `sceHttpParseResponseHeader` disagreed with a PS5 (firmware 13.60) in three ways, measured through the console's `libSceHttp.sprx` from a payload: 1. **An empty value returned the next header line.** For `Empty:\r\nSpaces: v \r\n…`, `main` returned `Spaces: v ` as the value of `Empty`; the leading-whitespace skip consumed the line break. The console returns 0 with a null value and length 0, and does not look for a later field of the same name (`E2:\r\nE2: second` is empty too). 2. **The return value counted the line break.** The console returns the offset of the value's end (`value - header + length`), for example 23 for `Content-Type: text/html\r\n…`; `main` returned 25. 3. **The value's end differs in a few line-break cases.** A value that runs to the end of the buffer keeps its final line break (`X: right\n` gives `right\n`, `X: abc\r\n\tdef\r\n` gives `abc\r\n\tdef\r\n`), and a bare line feed after the colon is skipped as whitespace (`X:\nY: z` gives `Y: z`), while the line feed of a CRLF is not (`X:\r\nY: z` is empty). The new code follows a model fitted to the console and then checked on data it had not seen: - every combination of up to 4 of {space, tab, CR, LF, `v`} after `X:`, alone and followed by `Y: z` (1,562 headers); - every combination of 5 of {space, CR, LF, `v`} (2,048); - every combination of 5 of {space, tab, CR, LF, `v`} (6,250); - the 20 inputs of the existing `guest_http_response_header` test and 16 mixed headers. The model matches all of them. It skips leading whitespace up to the line feed of a CRLF. It then ends the value at the first line feed followed by a character other than space or tab, without its carriage return when that line feed, or the value's first one, ends a CRLF; with no such line feed, at the end of the buffer. The existing test expectations came from shadPS4 and encoded the old results (`X:\r\nnext\r\n` gave `next`); they now hold the console's results. ### Tested - PS5 (firmware 13.60): about 9,900 headers through the console's `sceHttpParseResponseHeader`, compared with this implementation (no mismatch). - Linux: full CTest 1070/1071. `guest_http_response_header` fails with this PR's `Export.cpp` reverted and passes with it. `agc_driver_tessellation` segfaults the same way on `main`. - Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: CTest 1097 tests with no failures (the GPU tests skip in this VM). - No title I have calls this function, so this is console evidence only. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-14 02:26:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:26:03Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159508627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5476#issuecomment-6159508627). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:26:03Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5476
No description provided.