feat(libSceHttp): handle unknown Content-Range lengths #18309

Merged
Ondra97 merged 1 commit from upstream-pr/18309 into main 2026-11-13 00:58:16 +00:00
Ondra97 commented 2026-11-11 05:37:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-11-11T05:37:35Z.


What

Support a valid single-range response whose Content-Range complete length is *, as described in RFC 9110 section 14.4. The reusable host HTTP source currently sends that suffix to its numeric parser and refuses the response. Its size/seek interface still needs a definite source size.

Validate the returned range's start, span, non-empty body and requested length before using the existing unconditional full-response fallback. Determine the size from that complete response. The existing full-response checks verify identity and size when the source is already open, and reject a server that keeps returning partial responses. Compare the non-empty span without an overflowing last - first + 1 expression.

The real loopback regressions cover initial and later unknown lengths, fixed/chunked/close framing, ETag and Last-Modified identity, and an unvalidated complete snapshot. They reject malformed bounds, empty data, invalid length suffixes, unsupported units, repeated partial/refused/short fallbacks, changed identity or size, absent identity and redirects after opening. Request-history assertions verify the fallback sequence and that malformed partial responses are refused before a full retry. Failed later reads preserve output bytes, position and size.

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; the selected tests do not exercise it.

Upstream base: 527b309dd954b47fbf543d5ac6887fe90ef2c7ba. Tested head: 81d7b41f6b6500e9337dad2683443017355bfdf3.

Before editing production code, the new loopback matrix failed on that exact base: only the known-length control passed. All fourteen invalid cases were refused. The staged Windows runtime matched the rebuilt provider.

Metric Before (base) After (feature)
Accepted source cases, including the known-length control 1/8 8/8
Invalid cases refused 14/14 14/14

The production change built the full libraries, relinker and selected executables. All ten selected CTests passed, zero failed or skipped, each below 30 seconds: the reusable HTTP client, HTTP APIs/options/diagnostics/response headers, AvPlayer HTTP source and transport, patched HTTP/AvPlayer module integration, patched-library loading and the public-header audit. The new matrix also passed through the patched-module runner. All 407 patched libraries loaded; the audit checked 407 libraries and 33,863 exports.

After the combined check and final fixture placement, the exact standalone head was restored, the full production targets were rebuilt, and both directly affected integration tests passed again: guest_http_client and avplayer_http_patched_modules. Both exercise the 8/8 and 14/14 matrix. The staged Windows runtime was refreshed and its hash matches the rebuilt provider.

A local, uncommitted composition with #18248 (3cd55326910d752860725e4aa1b8d8dbd3028adb), #18270 (57452d7cc5c710e39044369c9d785b24a0be0885) and #18292 (e8b8026a8d2846b8535ff207b7b13033da43e958) merged cleanly, produced tree 4e620e395307b2defaa9e5d6a9c2f4324ba54b20, and passed both client modes. That includes the new 8/8 accepted and 14/14 refused cases, the 203 representation matrix, empty Content-Range cases, and the equivalent/conflicting Content-Length matrix. No console or title run was performed; this is host HTTP interoperability, with no title-unblock or performance claim.

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

cmake --build ../b --target relinker libs guest_http_client_tests guest_http_tests guest_http_options_tests guest_http_dbg_printf_tests guest_http_response_header_tests guest_avplayer_tests avplayer_http_transport_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)$' --parallel 4 -V --no-tests=error
python tools/check_conventions.py --base origin/main
python tools/pr_overlap.py --base main --branch codex/feat-http-unknown-range-length --repo boykopovar/AnyPS5 --jobs 4
git diff --check origin/main...HEAD

Conventions and whitespace checks passed. The final overlap tool checked 2,009 open PRs, compared all three related HTTP PRs successfully, and exited 0 with no overlap. The combined runtime result is above; no ordering dependency was found.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5254445586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18309). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-11T05:37:35Z. --- ### What Support a valid single-range response whose Content-Range complete length is `*`, as described in [RFC 9110 section 14.4](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.4). The reusable host HTTP source currently sends that suffix to its numeric parser and refuses the response. Its size/seek interface still needs a definite source size. Validate the returned range's start, span, non-empty body and requested length before using the existing unconditional full-response fallback. Determine the size from that complete response. The existing full-response checks verify identity and size when the source is already open, and reject a server that keeps returning partial responses. Compare the non-empty span without an overflowing `last - first + 1` expression. The real loopback regressions cover initial and later unknown lengths, fixed/chunked/close framing, ETag and Last-Modified identity, and an unvalidated complete snapshot. They reject malformed bounds, empty data, invalid length suffixes, unsupported units, repeated partial/refused/short fallbacks, changed identity or size, absent identity and redirects after opening. Request-history assertions verify the fallback sequence and that malformed partial responses are refused before a full retry. Failed later reads preserve output bytes, position and size. ### 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; the selected tests do not exercise it. Upstream base: `527b309dd954b47fbf543d5ac6887fe90ef2c7ba`. Tested head: `81d7b41f6b6500e9337dad2683443017355bfdf3`. Before editing production code, the new loopback matrix failed on that exact base: only the known-length control passed. All fourteen invalid cases were refused. The staged Windows runtime matched the rebuilt provider. | Metric | Before (base) | After (feature) | | --- | --- | --- | | Accepted source cases, including the known-length control | 1/8 | 8/8 | | Invalid cases refused | 14/14 | 14/14 | The production change built the full libraries, relinker and selected executables. All ten selected CTests passed, zero failed or skipped, each below 30 seconds: the reusable HTTP client, HTTP APIs/options/diagnostics/response headers, AvPlayer HTTP source and transport, patched HTTP/AvPlayer module integration, patched-library loading and the public-header audit. The new matrix also passed through the patched-module runner. All 407 patched libraries loaded; the audit checked 407 libraries and 33,863 exports. After the combined check and final fixture placement, the exact standalone head was restored, the full production targets were rebuilt, and both directly affected integration tests passed again: `guest_http_client` and `avplayer_http_patched_modules`. Both exercise the 8/8 and 14/14 matrix. The staged Windows runtime was refreshed and its hash matches the rebuilt provider. A local, uncommitted composition with #18248 (`3cd55326910d752860725e4aa1b8d8dbd3028adb`), #18270 (`57452d7cc5c710e39044369c9d785b24a0be0885`) and #18292 (`e8b8026a8d2846b8535ff207b7b13033da43e958`) merged cleanly, produced tree `4e620e395307b2defaa9e5d6a9c2f4324ba54b20`, and passed both client modes. That includes the new 8/8 accepted and 14/14 refused cases, the 203 representation matrix, empty Content-Range cases, and the equivalent/conflicting Content-Length matrix. No console or title run was performed; this is host HTTP interoperability, with no title-unblock or performance claim. Commands from the source checkout, with the supported toolchain on `PATH` and the local full build in `../b`: ```powershell cmake --build ../b --target relinker libs guest_http_client_tests guest_http_tests guest_http_options_tests guest_http_dbg_printf_tests guest_http_response_header_tests guest_avplayer_tests avplayer_http_transport_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)$' --parallel 4 -V --no-tests=error python tools/check_conventions.py --base origin/main python tools/pr_overlap.py --base main --branch codex/feat-http-unknown-range-length --repo boykopovar/AnyPS5 --jobs 4 git diff --check origin/main...HEAD ``` Conventions and whitespace checks passed. The final overlap tool checked 2,009 open PRs, compared all three related HTTP PRs successfully, and exited 0 with no overlap. The combined runtime result is above; no ordering dependency was found. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-11 05:43:10 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 81d7b41f6b:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_http_client_tests built cleanly.
  • CTest (guest_http_client):
    1/1 Test #3086: guest_http_client ................   Passed    1.96 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 #3086: guest_http_client ................***Failed    1.46 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified that the added slash == std::string::npos and slash <= dash checks prevent out-of-bounds substr access, and that dash >= 6 is guaranteed by the preceding 'bytes ' prefix match.
    • core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified that evaluating body.empty() and last < first before last - first != body.size() - 1 prevents unsigned underflow and eliminates integer overflow vulnerabilities present in the former last - first + 1 expression.
    • core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified fallback termination when completeLength == '*'; setting full = true forces an unconditional full GET where any subsequent non-200 or 206 response triggers HttpFailure via full && status != 200, preventing infinite request loops.
    • core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified representation validation on late unknown-length reads (initialized == true), ensuring that mismatched sizes (total != size), changed ETags, missing validators, or late redirects strictly throw HttpFailure without mutating client state or destination buffers.
    • core/libs/tests/GuestHttpClient.cpp & core/libs/tests/AvPlayerHttpServer.py: Verified test coverage across all 8 accepted scenarios (initial/late unknown length, chunked/closed framing, ETag/Last-Modified identity, unvalidated snapshots) and 14 rejected error scenarios (malformed bounds, empty bodies, invalid suffixes, repeated partials, short reads, changed identity/size/redirects).
    • AGENTS.md compliance: Verified zero disallowed comments were introduced in modified C++ code, no title-specific workarounds or stubs were added, and convention/diff/build/negative gates passed cleanly.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5854386481 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18309#pullrequestreview-5854386481). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T05:43:10Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `81d7b41f6b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_http_client_tests` built cleanly. - **CTest** (`guest_http_client`): ``` 1/1 Test #3086: guest_http_client ................ Passed 1.96 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 #3086: guest_http_client ................***Failed 1.46 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified that the added slash == std::string::npos and slash <= dash checks prevent out-of-bounds substr access, and that dash >= 6 is guaranteed by the preceding 'bytes ' prefix match. - core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified that evaluating body.empty() and last < first before last - first != body.size() - 1 prevents unsigned underflow and eliminates integer overflow vulnerabilities present in the former last - first + 1 expression. - core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified fallback termination when completeLength == '*'; setting full = true forces an unconditional full GET where any subsequent non-200 or 206 response triggers HttpFailure via full && status != 200, preventing infinite request loops. - core/libs/prx/libSceHttp/src/Client.cpp (HttpClientState::Fetch): Verified representation validation on late unknown-length reads (initialized == true), ensuring that mismatched sizes (total != size), changed ETags, missing validators, or late redirects strictly throw HttpFailure without mutating client state or destination buffers. - core/libs/tests/GuestHttpClient.cpp & core/libs/tests/AvPlayerHttpServer.py: Verified test coverage across all 8 accepted scenarios (initial/late unknown length, chunked/closed framing, ETag/Last-Modified identity, unvalidated snapshots) and 14 rejected error scenarios (malformed bounds, empty bodies, invalid suffixes, repeated partials, short reads, changed identity/size/redirects). - AGENTS.md compliance: Verified zero disallowed comments were introduced in modified C++ code, no title-specific workarounds or stubs were added, and convention/diff/build/negative gates passed cleanly. - Note: the AI-assisted checkbox can stay. Looks Good To Me
MarcZX10 commented 2026-11-12 16:49:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T16:49:04Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

Head reviewed: 81d7b41f6b6500e9337dad2683443017355bfdf3, base main. Title: "feat(libSceHttp): handle unknown Content-Range lengths".

What I ran

  • Read the review folder: description, commits, manifest, diff, and the head text of the three changed files.
  • Read the head source of Client.cpp around the fetch loop (lines 360 to 539) and checked the new * branch against the full-response checks.
  • No build and no test was run. Test and build results come from the description and are not verified here.

Results

Check Result Note
Source logic, Client.cpp passed Bounds checked before the * branch
Description claims vs code passed Fallback and identity checks match
Build and CTest not run Author-reported, Windows
Loopback matrix 8/8, 14/14 not run Author-reported
Conventions and overlap not run Author-reported

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceHttp/src/Client.cpp:478: a 206 with * as the complete length makes the client request the whole source. On open, that full response is kept in memory (cache = std::move(body), line 507), so a large file takes its full size in RAM. This follows the description's design. Consider saying so in the description, or adding a size limit.

Not verified

  • Nothing was built or run here. CTest, the loopback matrix, and the convention and overlap checks are author-reported only.
  • Negative control: the author reports the new matrix failed on the base (1/8 accepted). I did not run that.
  • Number() was not read. The refusals for missing-total, bad-total and overflow-span do not depend on it, because the span or last >= total check refuses them anyway.
  • AvPlayerHttpServer.py was read only through its changed hunks and imports. GuestHttpClient.cpp was read only through its changed hunks. The callers of Fetch (Read, Seek) and the Connection class were not read, so the request history in the "known" case (end byte 99999) is not confirmed against the caller.

Files: 3 of 3 reviewed files read (two only by changed hunk). Excluded by rule: none.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5878453685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18309#pullrequestreview-5878453685). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T16:49:04Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. Head reviewed: `81d7b41f6b6500e9337dad2683443017355bfdf3`, base `main`. Title: "feat(libSceHttp): handle unknown Content-Range lengths". ## What I ran - Read the review folder: description, commits, manifest, diff, and the head text of the three changed files. - Read the head source of `Client.cpp` around the fetch loop (lines 360 to 539) and checked the new `*` branch against the full-response checks. - No build and no test was run. Test and build results come from the description and are not verified here. ## Results | Check | Result | Note | | --- | --- | --- | | Source logic, `Client.cpp` | passed | Bounds checked before the `*` branch | | Description claims vs code | passed | Fallback and identity checks match | | Build and CTest | not run | Author-reported, Windows | | Loopback matrix 8/8, 14/14 | not run | Author-reported | | Conventions and overlap | not run | Author-reported | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceHttp/src/Client.cpp:478`: a `206` with `*` as the complete length makes the client request the whole source. On open, that full response is kept in memory (`cache = std::move(body)`, line 507), so a large file takes its full size in RAM. This follows the description's design. Consider saying so in the description, or adding a size limit. ## Not verified - Nothing was built or run here. CTest, the loopback matrix, and the convention and overlap checks are author-reported only. - Negative control: the author reports the new matrix failed on the base (1/8 accepted). I did not run that. - `Number()` was not read. The refusals for `missing-total`, `bad-total` and `overflow-span` do not depend on it, because the span or `last >= total` check refuses them anyway. - `AvPlayerHttpServer.py` was read only through its changed hunks and imports. `GuestHttpClient.cpp` was read only through its changed hunks. The callers of `Fetch` (`Read`, `Seek`) and the `Connection` class were not read, so the request history in the "known" case (end byte 99999) is not confirmed against the caller. Files: 3 of 3 reviewed files read (two only by changed hunk). Excluded by rule: none. ## 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!18309
No description provided.