fix(libSceHttp): reject repeated transfer-coding fields #18346

Merged
Ondra97 merged 4 commits from upstream-pr/18346 into main 2026-11-14 00:10:22 +00:00
Ondra97 commented 2026-11-11 10:54:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-11-11T10:54:17Z.


What

Depends on #18332, included in this branch together with its #18292 prerequisite; merge them first. Both changes touch the duplicate-header guard. The prerequisite's numerical Content-Length recovery is retained, with a separate refusal for a repeated Transfer-Encoding field.

The client currently drops a second Transfer-Encoding: chunked when its text matches the first field. The equivalent comma-joined coding chain is already refused. This silently changes the declared coding chain and also accepts a later contradictory response. RFC 9110 field-line combination preserves the ordered values; RFC 9112 section 6.1 prohibits a sender from applying chunked twice. Refuse repeated transfer-coding fields under the helper's existing single-chunked policy.

The real HTTP fixture covers complete, ranged and empty bodies; a single field with case/OWS variants remains valid. Refusals cover repeated fields, mixed field-name casing, surrounding whitespace, three fields, joined/mixed coding chains and empty members. A late repeated field must leave the destination byte, source size, position and previously cached bytes intact.

Tested

Windows 11 Pro 26300, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, ANYPS5_ENABLE_SPIRV_TOOLS=ON. CPU: AMD Ryzen 9 7900X. RAM: 31.66 GiB usable. GPU: NVIDIA GeForce RTX 4070 Ti SUPER; these tests do not exercise it.

Upstream base: 71ce4789567dfd2c7c4e64779365ea35f8d14174. Standalone fix: 488e8f64d2238e7d3e1631a28308710b1f77244a. Tested final head: 8202f9c05d5ffa9061451f6c7207cb0a24e7aed8, including #18332 at 67b3f6b3ce63a4494cb3150a103ff5e40485e590 and #18292 at e8b8026a8d2846b8535ff207b7b13033da43e958.

Before editing production code, the exact main passed 9/9 valid controls but refused only 15/27 invalid cases and accepted the late duplicate. With the standalone fix, it passes 9/9, refuses 27/27 and passes the late state-preservation check. Refusal controls accept either an Open failure or the helper's existing unsupported-coding exception; they verify that no source remains open.

The final exact head built the full production libraries, relinker and selected executables. All 11 selected CTests passed, zero failed or skipped, each below 30 seconds. Both direct and actually loaded patched-module client runs report 9/9 transfer controls, 27/27 invalid fields refused and 1/1 late refusal; the inherited Content-Length matrix also remains 45/45 accepted, 72/72 refused and 1/1 late refusal. AvPlayer transport, HTTP exports/options/header parsing/diagnostics, debt-length and the public-header/library-load checks passed. All 407 patched libraries loaded; the audit checked 407 libraries and 33,962 exports.

Combined the exact head locally with #18248, #18270, #18309 and #18317, including their declared prerequisites. Tree 1e382c005790793f3a71361d790d22ebd620e000 passed all four selected direct-client, HTTP 203 representation, patched-module and fixed-clock date CTests. The transfer/length matrices run in the direct and patched-module client tests; the 203 test runs its representation matrix. After restoring the exact standalone head, full production targets were rebuilt and all 11 standalone CTests passed again. Each test completed below 30 seconds. The staged Windows provider hash matches the rebuilt provider.

Commands from the source checkout, with the supported toolchain on PATH and the full build in ../b:

cmake --build ../b --target relinker libs guest_http_client_tests guest_http_tests guest_http_response_header_tests guest_http_options_tests guest_http_dbg_printf_tests guest_avplayer_tests avplayer_http_transport_tests avplayer_http_patched_modules_tests patched_libraries_tests --parallel 10
cmake -DDEST_DIR=../b/tests -P cmake/CopyRuntimeFiles.cmake ../b/core/libs/libs/unpatched/libSceHttp.prx
ctest --test-dir ../b -R '^(guest_http(_client|_dbg_printf|_options|_response_header)?|guest_avplayer_http|avplayer_http_(transport|patched_modules)|public_headers|patched_libraries|conventions_debt_length)$' --parallel 4 -V --no-tests=error
python tools/check_conventions.py --base origin/main
python tools/pr_overlap.py --base main --branch codex/fix-http-repeated-transfer-coding --repo boykopovar/AnyPS5 --jobs 4
git diff --check origin/main...HEAD

Conventions and whitespace checks passed. The final overlap check fetched 1,977 open heads and examined 1,975 candidates after excluding the two included prerequisites. It compared all four shared-file branches successfully and exited 0 with no overlap. The prerequisite remains explicit in Depends on; the transfer fixture is grouped with the length fixture so it merges cleanly with the separate status/date fixtures.

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 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: #18332
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5258148950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18346). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-11T10:54:17Z. --- ### What Depends on #18332, included in this branch together with its #18292 prerequisite; merge them first. Both changes touch the duplicate-header guard. The prerequisite's numerical Content-Length recovery is retained, with a separate refusal for a repeated Transfer-Encoding field. The client currently drops a second `Transfer-Encoding: chunked` when its text matches the first field. The equivalent comma-joined coding chain is already refused. This silently changes the declared coding chain and also accepts a later contradictory response. [RFC 9110 field-line combination](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.3) preserves the ordered values; [RFC 9112 section 6.1](https://www.rfc-editor.org/rfc/rfc9112.html#section-6.1) prohibits a sender from applying chunked twice. Refuse repeated transfer-coding fields under the helper's existing single-chunked policy. The real HTTP fixture covers complete, ranged and empty bodies; a single field with case/OWS variants remains valid. Refusals cover repeated fields, mixed field-name casing, surrounding whitespace, three fields, joined/mixed coding chains and empty members. A late repeated field must leave the destination byte, source size, position and previously cached bytes intact. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 26300, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. CPU: AMD Ryzen 9 7900X. RAM: 31.66 GiB usable. GPU: NVIDIA GeForce RTX 4070 Ti SUPER; these tests do not exercise it. Upstream base: `71ce4789567dfd2c7c4e64779365ea35f8d14174`. Standalone fix: `488e8f64d2238e7d3e1631a28308710b1f77244a`. Tested final head: `8202f9c05d5ffa9061451f6c7207cb0a24e7aed8`, including #18332 at `67b3f6b3ce63a4494cb3150a103ff5e40485e590` and #18292 at `e8b8026a8d2846b8535ff207b7b13033da43e958`. Before editing production code, the exact main passed 9/9 valid controls but refused only 15/27 invalid cases and accepted the late duplicate. With the standalone fix, it passes 9/9, refuses 27/27 and passes the late state-preservation check. Refusal controls accept either an Open failure or the helper's existing unsupported-coding exception; they verify that no source remains open. The final exact head built the full production libraries, relinker and selected executables. All 11 selected CTests passed, zero failed or skipped, each below 30 seconds. Both direct and actually loaded patched-module client runs report 9/9 transfer controls, 27/27 invalid fields refused and 1/1 late refusal; the inherited Content-Length matrix also remains 45/45 accepted, 72/72 refused and 1/1 late refusal. AvPlayer transport, HTTP exports/options/header parsing/diagnostics, debt-length and the public-header/library-load checks passed. All 407 patched libraries loaded; the audit checked 407 libraries and 33,962 exports. Combined the exact head locally with #18248, #18270, #18309 and #18317, including their declared prerequisites. Tree `1e382c005790793f3a71361d790d22ebd620e000` passed all four selected direct-client, HTTP 203 representation, patched-module and fixed-clock date CTests. The transfer/length matrices run in the direct and patched-module client tests; the 203 test runs its representation matrix. After restoring the exact standalone head, full production targets were rebuilt and all 11 standalone CTests passed again. Each test completed below 30 seconds. The staged Windows provider hash matches the rebuilt provider. Commands from the source checkout, with the supported toolchain on `PATH` and the full build in `../b`: ```powershell cmake --build ../b --target relinker libs guest_http_client_tests guest_http_tests guest_http_response_header_tests guest_http_options_tests guest_http_dbg_printf_tests guest_avplayer_tests avplayer_http_transport_tests avplayer_http_patched_modules_tests patched_libraries_tests --parallel 10 cmake -DDEST_DIR=../b/tests -P cmake/CopyRuntimeFiles.cmake ../b/core/libs/libs/unpatched/libSceHttp.prx ctest --test-dir ../b -R '^(guest_http(_client|_dbg_printf|_options|_response_header)?|guest_avplayer_http|avplayer_http_(transport|patched_modules)|public_headers|patched_libraries|conventions_debt_length)$' --parallel 4 -V --no-tests=error python tools/check_conventions.py --base origin/main python tools/pr_overlap.py --base main --branch codex/fix-http-repeated-transfer-coding --repo boykopovar/AnyPS5 --jobs 4 git diff --check origin/main...HEAD ``` Conventions and whitespace checks passed. The final overlap check fetched 1,977 open heads and examined 1,975 candidates after excluding the two included prerequisites. It compared all four shared-file branches successfully and exited 0 with no overlap. The prerequisite remains explicit in Depends on; the transfer fixture is grouped with the length fixture so it merges cleanly with the separate status/date fixtures. ### 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 - [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 - [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: #18332 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-11 15:55:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T15:55:43Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8202f9c05d:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_http_client_tests built cleanly.
  • CTest (guest_http_client):
    1/1 Test #3109: guest_http_client ................   Passed    1.78 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceHttp/src/Client.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3109: guest_http_client ................***Failed    1.07 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libSceHttp/src/Client.cpp that HttpClientState::Fetch throws HttpFailure("repeated HTTP transfer coding fields") whenever an incoming header matches name == "transfer-encoding" and !inserted is true, properly refusing both identical and distinct repeated fields across all casing variants.
    • Verified in core/libs/prx/libSceHttp/src/Client.cpp that ContentLength parses comma-delimited content length lists using std::from_chars, validates identical values across entries and duplicate headers, handles prefix/suffix/empty tokens safely without infinite loops or buffer overruns, and throws HttpFailure on conflict.
    • Verified state preservation in HttpClientState::Fetch: state fields (url, cache, cacheStart, size, position, validator, etag) remain unmodified on failure because mutations occur strictly after full header and body validation, as exercised by the late duplicate refusal tests.
    • Verified LP64 and LLP64 portability and type safety across Linux x86_64 and Windows MinGW-w64 GCC targets with consistent use of std::uint64_t, std::size_t, and std::string_view.
    • Verified test coverage in core/libs/tests/GuestHttpClient.cpp and core/libs/tests/AvPlayerHttpServer.py covering 9 valid controls, 27 invalid transfer encoding variations (repeated, ows, mixed-case, triple, joined, mixed coding chains), and late duplicate refusal with preserved state, corroborated by clean negative gate verification.
    • Verified full compliance with AGENTS.md conventions: zero comments introduced in code, no special-cased title IDs or trace magic paths, no extra files or unauthorized third-party libraries, and valid Conventional Commit formatting.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5861541258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18346#pullrequestreview-5861541258). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T15:55:43Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `8202f9c05d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_http_client_tests` built cleanly. - **CTest** (`guest_http_client`): ``` 1/1 Test #3109: guest_http_client ................ Passed 1.78 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceHttp/src/Client.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3109: guest_http_client ................***Failed 1.07 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libSceHttp/src/Client.cpp that HttpClientState::Fetch throws HttpFailure("repeated HTTP transfer coding fields") whenever an incoming header matches name == "transfer-encoding" and !inserted is true, properly refusing both identical and distinct repeated fields across all casing variants. - Verified in core/libs/prx/libSceHttp/src/Client.cpp that ContentLength parses comma-delimited content length lists using std::from_chars, validates identical values across entries and duplicate headers, handles prefix/suffix/empty tokens safely without infinite loops or buffer overruns, and throws HttpFailure on conflict. - Verified state preservation in HttpClientState::Fetch: state fields (url, cache, cacheStart, size, position, validator, etag) remain unmodified on failure because mutations occur strictly after full header and body validation, as exercised by the late duplicate refusal tests. - Verified LP64 and LLP64 portability and type safety across Linux x86_64 and Windows MinGW-w64 GCC targets with consistent use of std::uint64_t, std::size_t, and std::string_view. - Verified test coverage in core/libs/tests/GuestHttpClient.cpp and core/libs/tests/AvPlayerHttpServer.py covering 9 valid controls, 27 invalid transfer encoding variations (repeated, ows, mixed-case, triple, joined, mixed coding chains), and late duplicate refusal with preserved state, corroborated by clean negative gate verification. - Verified full compliance with AGENTS.md conventions: zero comments introduced in code, no special-cased title IDs or trace magic paths, no extra files or unauthorized third-party libraries, and valid Conventional Commit formatting. - Note: the AI-assisted checkbox can stay. Looks Good To Me
MarcZX10 commented 2026-11-12 15:39:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T15:39:07Z.

Review: COMMENTED


Reviewed libSceHttp repeated transfer-coding refusal — no blocking findings

Nothing blocks this; no optional points remain.

What I ran

  • Head: 8202f9c05d5ffa9061451f6c7207cb0a24e7aed8. Base: main. The description says the branch includes #18332 and #18292; the diff against main already contains both.
  • No build and no test run in this pass. Author-reported Windows results were not run here.
  • Inspections: diff.patch, description.md, commits.md, manifest.json, files.json, and the head text of Client.cpp under files/, read by targeted search and by ranges around Open, ContentLength, Number and Field.
  • Not run: the repository's check_conventions.py, pr_precheck.py, git diff --check, and the review-body validator (not checked whether it is present).

Results

Check Result Note
Diff read, 3 changed files passed Hunks read in full
Head context, Client.cpp passed Number rejects empty and out-of-range input
Case counts in GuestHttpClient.cpp passed 9 + 27 + 1 and 45 + 72 + 1 match the lists
Build and CTest not run Author-reported only
Conventions and whitespace not run Author-reported only
Commands and inspections

Inspections were made with the file search and the file reader on files/ and the diff. No shell command was run in this pass.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

  • No build and no run. The author's Windows results (MinGW GCC 15.2.0, 11 CTests, 407 patched libraries) are not confirmed here.
  • AvPlayerHttpServer.py: read through the diff and the import list only. The respond routing and the rest of the handler were not read.
  • GuestHttpClient.cpp: read through the diff only. The helpers Create, Read, End and Check were not read.
  • The author's late-duplicate claims (destination byte, source size and cache intact after refusal) depend on the runtime behaviour of Seek and Read, which I did not trace beyond the code above.
  • The overlap check with the other open pull requests was not repeated.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5877338428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18346#pullrequestreview-5877338428). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T15:39:07Z. **Review:** COMMENTED --- # Reviewed libSceHttp repeated transfer-coding refusal — no blocking findings Nothing blocks this; no optional points remain. ## What I ran - Head: `8202f9c05d5ffa9061451f6c7207cb0a24e7aed8`. Base: `main`. The description says the branch includes #18332 and #18292; the diff against `main` already contains both. - No build and no test run in this pass. Author-reported Windows results were not run here. - Inspections: `diff.patch`, `description.md`, `commits.md`, `manifest.json`, `files.json`, and the head text of `Client.cpp` under `files/`, read by targeted search and by ranges around `Open`, `ContentLength`, `Number` and `Field`. - Not run: the repository's `check_conventions.py`, `pr_precheck.py`, `git diff --check`, and the review-body validator (not checked whether it is present). ## Results | Check | Result | Note | |---|---|---| | Diff read, 3 changed files | passed | Hunks read in full | | Head context, `Client.cpp` | passed | `Number` rejects empty and out-of-range input | | Case counts in `GuestHttpClient.cpp` | passed | 9 + 27 + 1 and 45 + 72 + 1 match the lists | | Build and CTest | not run | Author-reported only | | Conventions and whitespace | not run | Author-reported only | <details> <summary>Commands and inspections</summary> Inspections were made with the file search and the file reader on `files/` and the diff. No shell command was run in this pass. </details> ## Findings **Blocking** None. **Non-blocking** None. ## Sources - `Client.cpp` repeated Transfer-Encoding refusal: https://github.com/boykopovar/AnyPS5/blob/8202f9c05d5ffa9061451f6c7207cb0a24e7aed8/core/libs/prx/libSceHttp/src/Client.cpp#L412-L417 - `Client.cpp` Content-Length list parsing: https://github.com/boykopovar/AnyPS5/blob/8202f9c05d5ffa9061451f6c7207cb0a24e7aed8/core/libs/prx/libSceHttp/src/Client.cpp#L60-L71 - `Client.cpp` Content-Length body path: https://github.com/boykopovar/AnyPS5/blob/8202f9c05d5ffa9061451f6c7207cb0a24e7aed8/core/libs/prx/libSceHttp/src/Client.cpp#L461 - `Client.cpp` `Open` returns 0 on `HttpFailure`: https://github.com/boykopovar/AnyPS5/blob/8202f9c05d5ffa9061451f6c7207cb0a24e7aed8/core/libs/prx/libSceHttp/src/Client.cpp#L546-L555 - RFC 9110 §5.3 and RFC 9112 §6.1 are cited by the description; I did not check their text. ## Not verified - No build and no run. The author's Windows results (MinGW GCC 15.2.0, 11 CTests, 407 patched libraries) are not confirmed here. - `AvPlayerHttpServer.py`: read through the diff and the import list only. The `respond` routing and the rest of the handler were not read. - `GuestHttpClient.cpp`: read through the diff only. The helpers `Create`, `Read`, `End` and `Check` were not read. - The author's late-duplicate claims (destination byte, source size and cache intact after refusal) depend on the runtime behaviour of `Seek` and `Read`, which I did not trace beyond the code above. - The overlap check with the other open pull requests was not repeated. ## To get this to a good state Nothing is required.
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!18346
No description provided.