Skip to content

fix(libSceFreeType): report guest-input throws as faults - #29230

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
upipibi:freetype-guest-faults
Dec 6, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
upipibi:freetype-guest-faults

Conversation

@upipibi

@upipibi upipibi commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Eight libSceFreeType exports forward every valid input to the bundled FreeType 2.13.3 but still reached NotImplemented_nid_no_patch on guest-input paths: an unreadable or misaligned FT_Library handle (one this module did not create), an unreadable module name, an unreadable FT_Memory record, face or size request. FreeType 2.13.3 dereferences each of these pointers for a non-null input, so this moves the sites to GuestFault_nid_no_patch (#28739). Part of #23391's per-library migration; same approach as #28912 (libharfbuzz) and #28898 (libcairo).

Sites, checked against FreeType 2.13.3 at the commit docs/dev/debt/libSceFreeType.md cites (42608f77f2):

  • ModuleManagement.cpp: the library handle read by FT_Get_Module, FT_Get_Renderer, FT_Remove_Module and FT_Add_Default_Modules. FreeType reads library->modules (ftobjs.c:5199), library->renderers.head through FT_Lookup_Renderer (ftobjs.c:4537), library->modules for a non-null module (ftobjs.c:5288) and library->num_modules through FT_Add_Module (ftobjs.c:5098). The module name copy: FT_Get_Module compares it with ft_strcmp (ftobjs.c:5203).
  • OutlineStorage.cpp: FT_Outline_New and FT_Outline_Done read library->memory (ftoutln.c:316, ftoutln.c:450).
  • Variations.cpp: FT_Done_MM_Var reads library->memory (ftmm.c:159).
  • BuildInfo.cpp: FT_Get_TrueType_Engine_Type calls FT_Get_Module on a non-null library (ftobjs.c:5683).
  • Export.cpp: FT_New_Library allocates through the FT_Memory record (ftobjs.c:5507).
  • SizeRequest.cpp: FT_Request_Size reads face->size and req->width (ftobjs.c:3456-3459).

Behaviour change, following the same source: FT_Get_Module with a null name returns null, and FT_Remove_Module with a null module returns FT_Err_Invalid_Driver_Handle, before the library is read (ftobjs.c:5196, ftobjs.c:5286). Before, an unreadable library with a null name or module threw.

Left as NotImplemented_nid_no_patch: a size request wider than the host FT_Long (Windows), FT_Done_FreeType of a library made with a guest FT_Memory, the FT_Outline_Render probe on an unsupported host, and the LCD filter exports (the console's build options are not known). Glyph.cpp, CacheManager.cpp and the property exports are left to #28019 and #27220.

Console behaviour is not measured. No title is known to be unblocked.

Changed libraries (implemented exports)

Library Before After Change
libSceFreeType 137/155 (88.39%) 145/155 (93.55%) +5.16%

Tested

Windows 11 Pro 10.0.26100, Ryzen 9 5950X, WinLibs MinGW-w64 GCC, Release, on main 67da974831.

  • ctest -R freetype: 116 of 116 passed.
  • guest_freetype_module_management, guest_freetype_build_info, guest_freetype_variations, guest_freetype_outline_storage, guest_freetype_request_size and guest_freetype_library_object: 3 of 3 runs each.
  • Negative control: the four updated tests with core/libs/prx/libSceFreeType from main fail (0 of 4).
  • tools/check_conventions.py passes; tools/pr_overlap.py --branch: no overlap with the 1698 open pull requests.

Not tested: Linux, macOS, 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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (Claude Code, Claude Opus 5.5)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Invalid or unreadable FreeType inputs now report a fault instead of an “not implemented” error.
    • Module lookup now returns no result when given a null library or module name.
    • Removing a module with a null library or module now returns the appropriate error code.

Move the unreadable-pointer rejections in the module, outline-storage,
variations, build-info, size-request and FT_New_Library paths from
NotImplemented_nid_no_patch to GuestFault_nid_no_patch (boykopovar#28739). FreeType
2.13.3 dereferences each of these pointers for a non-null input.

FT_Get_Module with a null name and FT_Remove_Module with a null module now
return before reading the library, as FreeType does, instead of throwing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: FreeType input handling

Layer / File(s) Summary
Guest-memory fault handling
core/libs/prx/libSceFreeType/Export.cpp, core/libs/prx/libSceFreeType/src/BuildInfo.cpp, core/libs/prx/libSceFreeType/src/ModuleManagement.cpp, core/libs/prx/libSceFreeType/src/OutlineStorage.cpp, core/libs/prx/libSceFreeType/src/SizeRequest.cpp, core/libs/prx/libSceFreeType/src/Variations.cpp, core/libs/tests/GuestFreeTypeBuildInfo.cpp, core/libs/tests/GuestFreeTypeOutlineStorage.cpp, core/libs/tests/GuestFreeTypeVariations.cpp
Guest-memory copy and validation failures now use GuestFault_nid_no_patch. Tests expect the fault message and continue to check errno where applicable.
Module null-argument handling
core/libs/prx/libSceFreeType/src/ModuleManagement.cpp, core/libs/tests/GuestFreeTypeModuleManagement.cpp
Module lookup returns nullptr for null library or module-name inputs. Module removal returns FT_Err_Invalid_Library_Handle for a null library and FT_Err_Invalid_Driver_Handle for a null module. Tests check these results and fault messages.

Possibly related issues

  • boykopovar/AnyPS5 issue 19123: It proposes a structural rule for guest pointer access. This PR changes FreeType exports to report guest-input faults, which addresses that behavior for this library.

Suggested reviewers: marczx10, zyylon, giannisg1

Change: Bug fix

Merge Risk: Minimal · up to b1dff

This change reports unreadable or misaligned FreeType guest inputs as faults instead of not-implemented, and gives defined results for null module arguments. No merge-blocking risk was found.

Security architecture risk: Minimal · up to b1dff

libSceFreeType now reports selected invalid guest inputs as faults rather than missing functionality. The affected operations still stop before the requested state change, and the review found no new path to a host operation. These faults no longer count as missing functions.

Security review details

Security Blast Radius

  • inferred — The demonstrated change is limited to rejection and diagnostics for callers of existing libSceFreeType exports. The inspected delta adds no host operation reachable after a failed read; the new null guards also stop before the host call.

Trust Boundaries and Controls

  • observed — The wrapper still checks alignment where it did before and uses libc's guest-copy helper before consuming the copied fields. Reclassifying a failed copy does not add provenance or lifetime validation for a successfully copied handle.

Public contracts

  • observed — FT_Get_Module returns nullptr when either argument is null. FT_Remove_Module returns Invalid_Library_Handle for a null library and Invalid_Driver_Handle for a null module with a non-null library. A null name or module can therefore produce a return even when the other, non-null argument is unreadable; that return does not validate the library.

Data and control flow

  • observed — FT_New_Library refuses an unreadable memory record before invoking the allocator bridge or publishing a handle. FT_Request_Size refuses a failed face or request read before changing or synchronizing the requested size. The outline and variation cleanup paths check the library before releasing storage.

Resilience and Maintainability Implications

  • observed — A reclassified failed read still aborts the current call by throwing; it does not complete the operation or guarantee guest recovery. It no longer increments the counter used by the libSceAgcDriver Performance Overlay or records a missing-function event in RunReport. If the fault reaches RunReport's termination hook with its message and an active collector, it is recorded as a generic runtime stop rather than a missing-function stop.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e0a01d34-01e5-499e-95c0-ea88dac381ef
Commits

Reviewing files that changed from the base of the PR and between ba2a804 and b1dffdf.

Files selected for processing: 10

  • core/libs/prx/libSceFreeType/Export.cpp
  • core/libs/prx/libSceFreeType/src/BuildInfo.cpp
  • core/libs/prx/libSceFreeType/src/ModuleManagement.cpp
  • core/libs/prx/libSceFreeType/src/OutlineStorage.cpp
  • core/libs/prx/libSceFreeType/src/SizeRequest.cpp
  • core/libs/prx/libSceFreeType/src/Variations.cpp
  • core/libs/tests/GuestFreeTypeBuildInfo.cpp
  • core/libs/tests/GuestFreeTypeModuleManagement.cpp
  • core/libs/tests/GuestFreeTypeOutlineStorage.cpp
  • core/libs/tests/GuestFreeTypeVariations.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head b1dffdfb476ac24d8bbe467b45c1aad71351f053 against the prepared diff and manifest. Used repo_read.py for source context. No tests or builds were run.

python3 repo_read.py cat core/libs/prx/libSceFreeType/src/ModuleManagement.cpp 1 76
python3 repo_read.py cat core/libs/prx/libSceFreeType/src/SizeRequest.cpp 1 40
python3 repo_read.py cat core/libs/prx/libSceFreeType/Export.cpp 175 205
python3 repo_read.py cat core/libs/prx/libSceFreeType/src/BuildInfo.cpp 1 74
python3 repo_read.py cat core/libs/prx/libSceFreeType/src/OutlineStorage.cpp 1 90
python3 repo_read.py cat core/libs/prx/libSceFreeType/src/Variations.cpp 1 55
python3 repo_read.py cat core/libs/tests/GuestFreeTypeModuleManagement.cpp 90 142
python3 repo_read.py cat core/libs/tests/GuestFreeTypeBuildInfo.cpp 1 152
python3 repo_read.py cat core/libs/tests/GuestFreeTypeOutlineStorage.cpp 90 158
python3 repo_read.py cat core/libs/tests/GuestFreeTypeVariations.cpp 140 180
python3 repo_read.py cat core/libs/tests/GuestFreeTypeRequestSize.cpp 175 205

Results

Check Result Note
Changed code review passed All 10 changed files reviewed; none excluded.
Tests and build not run The description reports Windows test results; not independently run.

Negative control

Not run; no tests were run during this review.

Findings

Blocking

None.

Non-blocking

None.

Sources

The changed wrappers convert unreadable guest input to guest faults and preserve the null-input paths described in the PR: ModuleManagement.cpp, OutlineStorage.cpp, SizeRequest.cpp, Variations.cpp, Export.cpp, and BuildInfo.cpp.

Not verified

Tests, builds, console behavior, and Linux/macOS behavior were not run or confirmed. All 10 changed files in the manifest were reviewed; files.json lists no exclusions.

To get this to a good state

Nothing required.

@github-actions github-actions Bot added the prx label Dec 6, 2026
@oneandonlydean
oneandonlydean merged commit c5c3c4e into boykopovar:main Dec 6, 2026
12 checks passed
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Progress report (ba2a804 → b1dffdf)

📈 System libraries: 49.18% (+0.02%, +8 implemented functions)

✅ 8 implemented
Library Name
libSceFreeType FT_Add_Default_Modules_nid_postfix
libSceFreeType FT_Done_MM_Var_nid_postfix
libSceFreeType FT_Get_Module_nid_postfix
libSceFreeType FT_Get_Renderer_nid_postfix
libSceFreeType FT_Get_TrueType_Engine_Type_nid_postfix
libSceFreeType FT_Outline_Done_nid_postfix
libSceFreeType FT_Outline_New_nid_postfix
libSceFreeType FT_Remove_Module_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceFreeType 137/155 (88.39%) 145/155 (93.55%) +5.16%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants