feat(http2): inflate gzip response bodies #12306

Merged
edubox merged 5 commits from upstream-pr/12306 into main 2026-10-30 15:20:46 +00:00
edubox commented 2026-10-28 08:38:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-28T08:38:15Z.


What

sceHttp2SetInflateGZIPEnabled threw for a nonzero argument. It now stores the flag. When the flag is set and the response carries content-encoding: gzip, the transport waits for END_STREAM, inflates the complete body, and only then serves it through sceHttp2ReadData and sceHttp2GetResponseContentLength, which report the inflated length. The transport does not add or inspect Accept-Encoding: the guest supplies that request header, and a gzip response is inflated while the option is enabled even if the guest did not request it.

The vendored zlib is built with NO_GZIP, so the transport parses the gzip header and trailer itself and inflates the payload as raw deflate; the CRC32 and ISIZE fields are verified. The initialized z_stream is released on every exit. Other encodings are not inflated. A malformed or truncated stream, concatenated members and an inflated body over 64 MiB throw. The console's header rewriting (Content-Encoding and Content-Length) is unverified and documented in the debt entry.

Tested

Linux (CachyOS), GCC 16.2.1, Release. guest_http2_transport adds Gzip, GzipSplit and GzipTruncated server modes: with the flag set, sceHttp2ReadData returns response body and sceHttp2GetResponseContentLength reports 13; GzipSplit sends the first 8 DATA bytes, defers the rest and reads in 3-byte pieces; GzipTruncated drops four trailer bytes and the read path throws; with the flag clear, the 33-byte compressed stream is returned unchanged. guest_http2* passes. Title: PPSA02195 enables inflate on its template on a tree with other local changes.

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 (textual conflicts with #12305 in Transport.cpp and the debt file; keep both sides. The same files overlap with #11134, #11470, #11611 and #11950, none of which implements gzip)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5047584705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12306). Originally posted by [edubox](https://github.com/edubox) on 2026-10-28T08:38:15Z. --- ### What `sceHttp2SetInflateGZIPEnabled` threw for a nonzero argument. It now stores the flag. When the flag is set and the response carries `content-encoding: gzip`, the transport waits for END_STREAM, inflates the complete body, and only then serves it through `sceHttp2ReadData` and `sceHttp2GetResponseContentLength`, which report the inflated length. The transport does not add or inspect `Accept-Encoding`: the guest supplies that request header, and a gzip response is inflated while the option is enabled even if the guest did not request it. The vendored zlib is built with `NO_GZIP`, so the transport parses the gzip header and trailer itself and inflates the payload as raw deflate; the CRC32 and ISIZE fields are verified. The initialized `z_stream` is released on every exit. Other encodings are not inflated. A malformed or truncated stream, concatenated members and an inflated body over 64 MiB throw. The console's header rewriting (Content-Encoding and Content-Length) is unverified and documented in the debt entry. ### Tested Linux (CachyOS), GCC 16.2.1, Release. `guest_http2_transport` adds `Gzip`, `GzipSplit` and `GzipTruncated` server modes: with the flag set, `sceHttp2ReadData` returns `response body` and `sceHttp2GetResponseContentLength` reports 13; `GzipSplit` sends the first 8 DATA bytes, defers the rest and reads in 3-byte pieces; `GzipTruncated` drops four trailer bytes and the read path throws; with the flag clear, the 33-byte compressed stream is returned unchanged. `guest_http2*` passes. Title: PPSA02195 enables inflate on its template on a tree with other local changes. ### 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 (textual conflicts with #12305 in `Transport.cpp` and the debt file; keep both sides. The same files overlap with #11134, #11470, #11611 and #11950, none of which implements gzip) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-28 08:48:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:48:16Z.

Review: CHANGES_REQUESTED


I found a cleanup issue on the malformed-response path. After inflateInit2 succeeds, every Require failure in the header parser, inflate loop, or trailer validation exits InflateGzip by exception before inflateEnd runs. A server that repeatedly returns malformed gzip data can therefore retain zlib state per failed request. Please guard the initialized z_stream with RAII (or equivalent cleanup on all exits) and add a malformed/truncated or bad-trailer regression that exercises the failure path. The current valid-gzip/passthrough test does not cover this. Windows CI and conventions pass; the focused transport tests are reported by the author on Linux, while hosted Linux is skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5679965424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12306#pullrequestreview-5679965424). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:48:16Z. **Review:** CHANGES_REQUESTED --- I found a cleanup issue on the malformed-response path. After `inflateInit2` succeeds, every `Require` failure in the header parser, inflate loop, or trailer validation exits `InflateGzip` by exception before `inflateEnd` runs. A server that repeatedly returns malformed gzip data can therefore retain zlib state per failed request. Please guard the initialized `z_stream` with RAII (or equivalent cleanup on all exits) and add a malformed/truncated or bad-trailer regression that exercises the failure path. The current valid-gzip/passthrough test does not cover this. Windows CI and conventions pass; the focused transport tests are reported by the author on Linux, while hosted Linux is skipped.
MarcZX10 commented 2026-10-28 09:11:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T09:11:14Z.

Review: CHANGES_REQUESTED


The head 4f58a9e35c is a rebase with no code changes, so the correctness gap remains: InflateGzip() is called only after END_STREAM, while Request::Read can return and drain DATA before that point. A split or >65,535-byte gzip response can therefore expose compressed bytes or pass only the tail to the inflater. Please buffer the complete encoded response before reads when inflation is enabled, or implement streaming inflate, and add a regression where DATA arrives in multiple reads before END_STREAM.

Also ensure inflateEnd runs on every error path and add an error-path test (malformed/truncated input or a bad trailer is sufficient to exercise cleanup). The existing valid-gzip/passthrough test does not cover the leak. Please state whether you expect Accept-Encoding to come from the guest; as written, the response is inflated whenever the option is enabled and the server answers gzip, whether or not the guest requested it. Author-reported Linux tests and conventions do not cover these cases, and hosted jobs are queued.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680214447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12306#pullrequestreview-5680214447). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T09:11:14Z. **Review:** CHANGES_REQUESTED --- The head `4f58a9e35c` is a rebase with no code changes, so the correctness gap remains: `InflateGzip()` is called only after END_STREAM, while `Request::Read` can return and drain DATA before that point. A split or >65,535-byte gzip response can therefore expose compressed bytes or pass only the tail to the inflater. Please buffer the complete encoded response before reads when inflation is enabled, or implement streaming inflate, and add a regression where DATA arrives in multiple reads before END_STREAM. Also ensure `inflateEnd` runs on every error path and add an error-path test (malformed/truncated input or a bad trailer is sufficient to exercise cleanup). The existing valid-gzip/passthrough test does not cover the leak. Please state whether you expect `Accept-Encoding` to come from the guest; as written, the response is inflated whenever the option is enabled and the server answers gzip, whether or not the guest requested it. Author-reported Linux tests and conventions do not cover these cases, and hosted jobs are queued.
adriadam10 commented 2026-10-28 11:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T11:38:13Z.

Review: CHANGES_REQUESTED


Thanks, the END_STREAM wait, the RAII z_stream guard and the flow-control consume cover the earlier review points; GzipSplit, GzipLarge and GzipTruncated pin the new behaviour.

One point is still open (raised by @oneandonlydean, not addressed on this head):

  • core/libs/tests/GuestHttp2Transport.cpp:415-501: the debt entry says a bad checksum, concatenated gzip members and the 64 MiB cap throw, but only the truncated stream is tested. Please add a server mode for a wrong CRC32 or ISIZE and one for two concatenated members, each asserting the read throws (Transport.cpp:365-371). The cap can stay untested if you drop it from the claim, or lower it behind a test constant.

Once those are in this is ready; the Transport.cpp and debt-file overlap with #12305 is mechanical and we will handle it when merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681988371 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12306#pullrequestreview-5681988371). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T11:38:13Z. **Review:** CHANGES_REQUESTED --- Thanks, the END_STREAM wait, the RAII `z_stream` guard and the flow-control consume cover the earlier review points; `GzipSplit`, `GzipLarge` and `GzipTruncated` pin the new behaviour. One point is still open (raised by @oneandonlydean, not addressed on this head): - `core/libs/tests/GuestHttp2Transport.cpp:415-501`: the debt entry says a bad checksum, concatenated gzip members and the 64 MiB cap throw, but only the truncated stream is tested. Please add a server mode for a wrong CRC32 or ISIZE and one for two concatenated members, each asserting the read throws (`Transport.cpp:365-371`). The cap can stay untested if you drop it from the claim, or lower it behind a test constant. Once those are in this is ready; the `Transport.cpp` and debt-file overlap with #12305 is mechanical and we will handle it when merging.
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!12306
No description provided.