Skip to content

fix(libfontconfig): read FreeType face and charmap through guest memory - #22685

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Treamyracle:fix-fontconfig-freetype-face-guest-read
Nov 24, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Treamyracle:fix-fontconfig-freetype-face-guest-read

Conversation

@Treamyracle

@Treamyracle Treamyracle commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

FcFreeTypeCharIndex in libfontconfig dereferenced face->charmap and charmap->encoding directly on the host, causing a segmentation fault or memory access violation when passed an unmapped guest face pointer or a face containing an unreadable charmap pointer. Read both fields safely through CopyGuestIn (GuestCopyIn_nid_no_patch), returning 0 if memory cannot be read. Update unit test GuestFontconfigCharIndex with unmapped face and charmap pointer checks, and fold the technical debt notes.

Tested

  • python tools/check_conventions.py --base upstream/main: All conventions checks passed.
  • python tools/guest_pointer_audit.py libfontconfig: The finding on FcFreeTypeCharIndex: parameter face (member) is eliminated (total findings reduced from 23 to 22).
  • python tools/pr_overlap.py --names FcFreeTypeCharIndex: Confirmed open: none across all open pull requests.
  • GuestFontconfigCharIndex: Added regressions verifying FcFreeTypeCharIndex returns 0 when passed an unmapped face pointer (0x10) or a face with an unmapped charmap pointer.

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

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 43c8cf2d92:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_fontconfig_char_index_tests built cleanly.
  • CTest (guest_fontconfig_char_index):
    1/1 Test #5258: guest_fontconfig_char_index ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libfontconfig/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5258: guest_fontconfig_char_index ......***Exception: SegFault  0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that FcFreeTypeCharIndex in Export.cpp safely accesses face->charmap and charmap->encoding using CopyGuestIn (GuestCopyIn_nid_no_patch) via ReadCharmapEncoding, returning 0 on invalid/unmapped guest memory.
    • Verified that ReadCharmapEncoding properly handles face->charmap == nullptr, setting encoding to 0 and hasCharmap to false without attempting to dereference null.
    • Verified loop logic in FcFreeTypeCharIndex over FT_ENCODING_UNICODE and FT_ENCODING_MS_SYMBOL, ensuring charmap re-query via ReadCharmapEncoding accurately inspects current encoding after FT_Select_Charmap_nid_postfix.
    • Verified AGENTS.md compliance: no comments in source code, technical debt fragment created under docs/dev/debt/changes/, no extra unauthorized files added.
    • Verified test coverage in GuestFontconfigCharIndex.cpp: assertions check null face, unmapped face pointer (0x10), and face with an unmapped charmap pointer (0x10).

Looks Good To Me

@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 in the inspected changes shows a blocking defect; the changed source and test support the stated guest memory safety fix.

What I ran

  • Reviewed head 43c8cf2d92c512ec15734f3dc67fcb418e396515 using repo_read.py.
  • Read the prepared description, commit summary, diff, manifest, and all three changed files. No tests or prechecks were run.

Results

Check Result Note
Source review passed All changed files read
Tests and prechecks not run Author reports checks in the PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Did not run GuestFontconfigCharIndex, conventions, guest pointer audit, or PR overlap checks; those runs are author-reported only.
  • Console Fontconfig version, call signature, and behavior are stated as unmeasured in the added debt note.
  • No excluded changed files were listed in the manifest; files.json was not available through the reader.

To get this to a good state

Nothing is required.

@ycbuzi

ycbuzi commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Tested 43c8cf2d92 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 4 tests failed out of 6181; 99% tests passed, 4 tests failed out of 6181. 4 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6181; 99% tests passed, 1 tests failed out of 6181. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@github-actions

github-actions Bot commented Nov 18, 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 17631 core/libs/prx/libfontconfig/Export.cpp

@Treamyracle

Treamyracle commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Manually checked PR 17631 (FcDefaultSubstitute) and PR 20181 (FcFontRenderPrepare): neither modifies FcFreeTypeCharIndex. Zero overlap.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 43c8cf2d92, applied with git apply on main fd4aeed483 together with the other 25 PRs of one batch (#24107, #24132, #24238, #15143, #22088, #23739, #24032, #16054, #20001, #20344, #24170, #24396, #16856, #17298, #20497, #23347, #24426, #24554, #24598, #21376, #21556, #22047, #22082, #14124, #18476). 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_fontconfig_char_index (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6524 tests) on the RTX 3080 has 8 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. Traced to other PRs of the batch, each by reverting it and testing again: #21556 (guest_json_allocator), #16856 (guest_kernel_sys_module_internal), #15143 (guest_math_exact); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): public_headers. 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)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants