Skip to content

fix(libfreetype): read GuestLibrary host handle safely - #22702

Open
plentilha wants to merge 2 commits into
boykopovar:mainfrom
plentilha:fix/libfreetype-library-host-guest-copy
Open

plentilha wants to merge 2 commits into
boykopovar:mainfrom
plentilha:fix/libfreetype-library-host-guest-copy

Conversation

@plentilha

Copy link
Copy Markdown
Contributor

What

Copy the guest FreeType::GuestLibrary::host handle through GuestCopyIn_nid_no_patch while preserving errno in FT_Library_SetLcdGeometry (core/libs/prx/libfreetype/src/LibraryHelpers.cpp) and FT_Bitmap_Blend (core/libs/prx/libfreetype/src/BitmapBlend.cpp), returning FT_Err_Invalid_Library_Handle and FT_Err_Invalid_Argument respectively when the GuestLibrary pointer is unreadable instead of dereferencing library->host directly, and add unreadable-handle tests preserving errno in GuestLegacyFreeTypeLibrary.cpp and GuestLegacyFreeTypeBitmapBlend.cpp.

Tested

Windows 11 (x86_64 MinGW): cmake --build build --target guest_legacy_freetype_library_tests guest_legacy_freetype_library_fixture guest_legacy_freetype_bitmap_blend_tests guest_legacy_freetype_bitmap_blend_fixture -j 8, ctest --test-dir build -R "^guest_legacy_freetype_(library|library_nid|bitmap_blend|bitmap_blend_nid)$" (4/4 passed), negative control confirmed failure on broken library host checks, guest_pointer_audit.py libfreetype (0 findings in LibraryHelpers.cpp and BitmapBlend.cpp), test_public_headers.py --audit-only, and check_conventions.py --base upstream/main.

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

@cocoa55

cocoa55 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

The code change looks right to me: CopyIn already saves and restores errno, and library->faces is only read after the host handle was read successfully.

The debt fragment adds a new entry under ### Functional, but libfreetype.md already has entries for FT_Library_SetLcdGeometry and FT_Bitmap_Blend under ### Library helpers. Those entries already describe refused host access as "host-boundary validation, not measured console behavior". This should probably be a ## change [FT_Bitmap_Blend] (and the same for FT_Library_SetLcdGeometry) that adds the unreadable-library case to the existing entries, not a second entry in another section.

Nit: the two files add a ReadLibraryHost helper with different signatures (one returns FT_Library, the other a bool with an out-parameter). With the first form, the !ReadLibraryHost(...) || !host check in LibraryHelpers.cpp would become a single test.

@plentilha
plentilha force-pushed the fix/libfreetype-library-host-guest-copy branch from 69a0c8e to 737e4a9 Compare November 18, 2026 09:46
This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 737e4a91ed, applied with git apply on main fd4aeed483 together with the other 28 PRs of one batch (#19470, #20317, #21336, #22189, #22888, #23474, #24467, #24489, #20216, #22048, #22111, #22319, #22422, #22841, #23127, #9547, #18247, #21720, #22375, #23405, #24134, #14851, #18324, #19650, #19986, #20447, #21078, #22362). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_legacy_freetype_bitmap_blend, guest_legacy_freetype_library (2 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6526 tests) on the RTX 3080 has 9 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked, guest_raise_short_sleep_without_wake, agc_driver_store_over_untracked. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_agc_driver_unknown, guest_load_ranges, tool_script_modes. The 2127 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@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 change; the unreadable library-handle checks use checked guest copies and preserve errno as described.

What I ran

Reviewed head 737e4a91ed410b9086c33175047cb787e1fe2855. No build or tests were run in this review; the Windows test results in the PR description are author-reported.

Results

Check Result Note
Changed code review passed Six changed files read
Build and tests not run PR description reports Windows checks

Findings

Blocking

None.

Non-blocking

None.

Not verified

No files were excluded: all six paths in the manifest were included and read. Runtime behavior, build results, and the reported negative control were not independently verified.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 26064 core/libs/tests/GuestLegacyFreeTypeBitmapBlend.cpp
core/libs/tests/GuestLegacyFreeTypeLibrary.cpp

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 24, 2026

This branch has not been deployed

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

Labels

docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants