feat(libfreetype): implement FT_Gzip_Uncompress #15439

Merged
VakzOs merged 2 commits from upstream-pr/15439 into main 2026-11-07 03:29:18 +00:00
VakzOs commented 2026-11-03 09:57:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by VakzOs on 2026-11-03T09:57:57Z.


What

The legacy libfreetype export hKvvpNeUdKo threw. The verified NID name database names it FT_Gzip_Uncompress, and tools/nid_names.py computes the same NID for that name. It is now implemented as FT_Gzip_Uncompress_nid_postfix in src/Gzip.cpp.

The call goes to the bundled FreeType 2.15.0 FT_Gzip_Uncompress, built with its internal zlib (FT_DISABLE_ZLIB only turns off the system zlib). A host FT_MemoryRec routes zlib's allocations to the guest FT_MemoryRec's alloc, free and realloc, reusing FreeType::GuestMemoryRec from libSceFreeType. Lengths cross as the console's 64-bit FT_ULong. On Windows, where FT_ULong is 32-bit, a length above ULONG_MAX returns Invalid_Argument before any cast. The output length is written back only on success, as FreeType does. The results are therefore FreeType's own:

  • Invalid_Argument for a null memory, output or length, and when inflateInit2 fails;
  • Array_Too_Large when the output is too small;
  • Invalid_Table for corrupt data;
  • Out_Of_Memory when inflate cannot allocate.

libfreetype gains a CMakeLists.txt that links freetype with --exclude-libs,ALL, as libSceFreeTypeOt does. The patched module exports hKvvpNeUdKo and no FT_* symbols.

The console's FreeType version and build options are unverified: a console FreeType built without zlib would return Unimplemented_Feature. docs/dev/debt/libfreetype.md records this.

Tested

Linux, GCC 13, Release: the new guest_legacy_freetype_gzip passes. It decodes a gzip stream and a zlib stream through guest memory callbacks, checks the text and length, and checks that every guest allocation is freed. It also covers the null-argument, short-output, corrupt-data and failed-inflateInit2 results, with the output length left unchanged on failure. Where unsigned long is 32-bit (the Windows CI job), it also checks both lengths at ULONG_MAX + 1. python3 tools/check_conventions.py --base origin/main passes.

tools/pr_overlap.py --branch reports one overlap, #15408 (libfreetype font metadata). Both PRs add core/libs/prx/libfreetype/CMakeLists.txt and touch adjacent lines in libfreetype.hpp and the debt file; no export is shared. I propose #15408 lands first and I rebase this onto it, adding src/Gzip.cpp and the test to its CMakeLists.txt.

Not tested on hardware or with a title.

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 (land order: #15408 first, then this PR)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5135245744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15439). Originally posted by [VakzOs](https://github.com/VakzOs) on 2026-11-03T09:57:57Z. --- ### What The legacy `libfreetype` export `hKvvpNeUdKo` threw. The [verified NID name database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv) names it `FT_Gzip_Uncompress`, and `tools/nid_names.py` computes the same NID for that name. It is now implemented as `FT_Gzip_Uncompress_nid_postfix` in `src/Gzip.cpp`. The call goes to the bundled FreeType 2.15.0 [`FT_Gzip_Uncompress`](https://github.com/freetype/freetype/blob/VER-2-15-0/src/gzip/ftgzip.c), built with its internal zlib (`FT_DISABLE_ZLIB` only turns off the system zlib). A host `FT_MemoryRec` routes zlib's allocations to the guest `FT_MemoryRec`'s `alloc`, `free` and `realloc`, reusing `FreeType::GuestMemoryRec` from libSceFreeType. Lengths cross as the console's 64-bit `FT_ULong`. On Windows, where `FT_ULong` is 32-bit, a length above `ULONG_MAX` returns `Invalid_Argument` before any cast. The output length is written back only on success, as FreeType does. The results are therefore FreeType's own: - `Invalid_Argument` for a null memory, output or length, and when `inflateInit2` fails; - `Array_Too_Large` when the output is too small; - `Invalid_Table` for corrupt data; - `Out_Of_Memory` when `inflate` cannot allocate. `libfreetype` gains a `CMakeLists.txt` that links `freetype` with `--exclude-libs,ALL`, as libSceFreeTypeOt does. The patched module exports `hKvvpNeUdKo` and no `FT_*` symbols. The console's FreeType version and build options are unverified: a console FreeType built without zlib would return `Unimplemented_Feature`. `docs/dev/debt/libfreetype.md` records this. ### Tested Linux, GCC 13, Release: the new `guest_legacy_freetype_gzip` passes. It decodes a gzip stream and a zlib stream through guest memory callbacks, checks the text and length, and checks that every guest allocation is freed. It also covers the null-argument, short-output, corrupt-data and failed-`inflateInit2` results, with the output length left unchanged on failure. Where `unsigned long` is 32-bit (the Windows CI job), it also checks both lengths at `ULONG_MAX + 1`. `python3 tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch` reports one overlap, #15408 (libfreetype font metadata). Both PRs add `core/libs/prx/libfreetype/CMakeLists.txt` and touch adjacent lines in `libfreetype.hpp` and the debt file; no export is shared. I propose #15408 lands first and I rebase this onto it, adding `src/Gzip.cpp` and the test to its `CMakeLists.txt`. Not tested on hardware or with a title. ### 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](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 (land order: #15408 first, then this PR) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!15439
No description provided.