refactor(libharfbuzz): report guest-input throws as faults #28912

Open
LODIBIDO wants to merge 1 commit from upstream-pr/28912 into main
LODIBIDO commented 2026-12-04 15:36:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LODIBIDO on 2026-12-04T15:36:34Z.


What

Six libharfbuzz exports forward every valid input to the pinned HarfBuzz 10.0.1 but still reached NotImplemented_nid_no_patch on guest-input paths: null handles, unreadable or unwritable guest pointers and buffers, a foreign or finalized FreeType face, a null blob with a nonzero length, or an out-of-range memory mode. Cairo-style, these are inputs the console module itself dereferences, so this moves the 22 sites to GuestFault_nid_no_patch (#28739). tools/progress.py counts it as a throw, so libharfbuzz goes from 30 of 37 on current main to 36 of 37.

This reproduces part of the closed #23897 by monika-runtime (credited as co-author) on current main, now that the GuestFault_nid_no_patch helper has merged; it is part of #23391's per-library migration, which the maintainers invited as separate PRs. The seventh export, hb_icu_get_unicode_funcs, is left to the open #28781.

Sites and their justification, checked against 3rdparty/harfbuzz at the pinned 10.0.1 commit:

  • Export.cpp hb_ft_face_create_cached (6): null face (hb-ft.cc dereferences ft_face->generic/stream), unreadable guest record, a record without a live AnyPS5 FreeType owner (foreign layout), unreadable owner fields or a null/finalized host face (released FT_Face), and the two unwritable generic copies.
  • Shaping.cpp hb_shape (3): null buffer (hb-shape.cc reads buffer->len), null font or a null feature array of nonzero length (null hb_memcpy source in hb-shape-plan.cc), and an unreadable feature array.
  • Lifecycle.cpp hb_blob_create (1): null data with a nonzero length below 2 GiB (stored and later read), and an out-of-range memory mode (out-of-range enum conversion, no upstream behaviour). A length of 2 GiB or more is upstream-rejected and is not faulted.
  • Layout.cpp (12): null faces, unreadable caller counts, a null tag array with a nonzero count, and the host-write bracket and later writes over unwritable count/tag/index buffers. A null count or index is documented as optional and is not faulted.

No control flow changes; the same inputs throw at the same points. The docs/dev/debt/libharfbuzz.md entries already describe these as throwing in place of upstream undefined behaviour, so no fragment is added.

Tested

Native Intel Mac (x86_64, macOS 15.7.8, Apple clang 17.0.0), Release, with the diffs of #27201 and #27767 applied locally.

  • ctest -R 'harfbuzz': 19 of 19 passed (the existing guest_harfbuzz_shape test already exercises the four hb_shape fault inputs and still counts four throws).
  • tools/progress.py --compare: libharfbuzz 30 to 36 of 37; no other library changes.
  • tools/check_conventions.py and tools/debt_fold.py --check: pass.

Not tested: Windows, Linux, console.

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 (part of #23391)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for invalid inputs and failed memory operations across font creation, layout queries, and text shaping.
    • These conditions now report guest faults rather than unimplemented operations; normal processing and return behavior are unchanged.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5649399587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28912). Originally posted by [LODIBIDO](https://github.com/LODIBIDO) on 2026-12-04T15:36:34Z. --- ### What Six libharfbuzz exports forward every valid input to the pinned HarfBuzz 10.0.1 but still reached `NotImplemented_nid_no_patch` on guest-input paths: null handles, unreadable or unwritable guest pointers and buffers, a foreign or finalized FreeType face, a null blob with a nonzero length, or an out-of-range memory mode. Cairo-style, these are inputs the console module itself dereferences, so this moves the 22 sites to `GuestFault_nid_no_patch` (#28739). `tools/progress.py` counts it as a throw, so libharfbuzz goes from 30 of 37 on current `main` to 36 of 37. This reproduces part of the closed #23897 by monika-runtime (credited as co-author) on current `main`, now that the `GuestFault_nid_no_patch` helper has merged; it is part of #23391's per-library migration, which the maintainers invited as separate PRs. The seventh export, `hb_icu_get_unicode_funcs`, is left to the open #28781. Sites and their justification, checked against `3rdparty/harfbuzz` at the pinned 10.0.1 commit: - `Export.cpp` `hb_ft_face_create_cached` (6): null face (`hb-ft.cc` dereferences `ft_face->generic`/`stream`), unreadable guest record, a record without a live AnyPS5 FreeType owner (foreign layout), unreadable owner fields or a null/finalized host face (released `FT_Face`), and the two unwritable `generic` copies. - `Shaping.cpp` `hb_shape` (3): null buffer (`hb-shape.cc` reads `buffer->len`), null font or a null feature array of nonzero length (null `hb_memcpy` source in `hb-shape-plan.cc`), and an unreadable feature array. - `Lifecycle.cpp` `hb_blob_create` (1): null data with a nonzero length below 2 GiB (stored and later read), and an out-of-range memory mode (out-of-range enum conversion, no upstream behaviour). A length of 2 GiB or more is upstream-rejected and is not faulted. - `Layout.cpp` (12): null faces, unreadable caller counts, a null tag array with a nonzero count, and the host-write bracket and later writes over unwritable count/tag/index buffers. A null `count` or `index` is documented as optional and is not faulted. No control flow changes; the same inputs throw at the same points. The `docs/dev/debt/libharfbuzz.md` entries already describe these as throwing in place of upstream undefined behaviour, so no fragment is added. ### Tested Native Intel Mac (x86_64, macOS 15.7.8, Apple clang 17.0.0), Release, with the diffs of #27201 and #27767 applied locally. - `ctest -R 'harfbuzz'`: 19 of 19 passed (the existing `guest_harfbuzz_shape` test already exercises the four `hb_shape` fault inputs and still counts four throws). - `tools/progress.py --compare`: `libharfbuzz` 30 to 36 of 37; no other library changes. - `tools/check_conventions.py` and `tools/debt_fold.py --check`: pass. Not tested: Windows, Linux, console. ### 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 and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 - [x] Fixes: none (part of #23391) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved error handling for invalid inputs and failed memory operations across font creation, layout queries, and text shaping. * These conditions now report guest faults rather than unimplemented operations; normal processing and return behavior are unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-12-04 16:34:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T16:34:51Z.

Review: APPROVED


Reviewed — looks good

The reviewed change consistently reports the identified guest-input failures as guest faults, and I found no blocking defects.

What I ran

Reviewed head 32f2923f2396a5ecbb3c2e34126e7da4b055fea2; no merged-preview check or tests were run. I read all four changed files listed under reviewed in files.json; files.json lists no excluded files.

sed -n '1,150p' files/core/libs/prx/libharfbuzz/Export.cpp
sed -n '1,150p' files/core/libs/prx/libharfbuzz/Layout.cpp
sed -n '1,150p' files/core/libs/prx/libharfbuzz/Lifecycle.cpp
sed -n '1,150p' files/core/libs/prx/libharfbuzz/Shaping.cpp
python3 repo_read.py search GuestFault_nid_no_patch core/libs/prx/libharfbuzz

The reader search printed matching lines but returned an error while trying to write its call log in the read-only review folder.

Results

Check Result Note
Changed-file review passed All four reviewed files read
Tests and build not run No tests or build invoked
Reader source search failed Matches printed; call logging failed

Negative control

Not run; no tests were run.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

Tests, Windows and Linux behavior, and console behavior were not verified. The description reports native Intel Mac test results; I did not run those checks.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6192765894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28912#pullrequestreview-6192765894). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T16:34:51Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change consistently reports the identified guest-input failures as guest faults, and I found no blocking defects. ## What I ran Reviewed head `32f2923f2396a5ecbb3c2e34126e7da4b055fea2`; no merged-preview check or tests were run. I read all four changed files listed under `reviewed` in `files.json`; `files.json` lists no excluded files. ```text sed -n '1,150p' files/core/libs/prx/libharfbuzz/Export.cpp sed -n '1,150p' files/core/libs/prx/libharfbuzz/Layout.cpp sed -n '1,150p' files/core/libs/prx/libharfbuzz/Lifecycle.cpp sed -n '1,150p' files/core/libs/prx/libharfbuzz/Shaping.cpp python3 repo_read.py search GuestFault_nid_no_patch core/libs/prx/libharfbuzz ``` The reader search printed matching lines but returned an error while trying to write its call log in the read-only review folder. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All four reviewed files read | | Tests and build | not run | No tests or build invoked | | Reader source search | failed | Matches printed; call logging failed | ## Negative control Not run; no tests were run. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Export.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/32f2923f2396a5ecbb3c2e34126e7da4b055fea2/core/libs/prx/libharfbuzz/Export.cpp) - [Layout.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/32f2923f2396a5ecbb3c2e34126e7da4b055fea2/core/libs/prx/libharfbuzz/Layout.cpp) - [Lifecycle.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/32f2923f2396a5ecbb3c2e34126e7da4b055fea2/core/libs/prx/libharfbuzz/Lifecycle.cpp) - [Shaping.cpp at reviewed head](https://github.com/boykopovar/AnyPS5/blob/32f2923f2396a5ecbb3c2e34126e7da4b055fea2/core/libs/prx/libharfbuzz/Shaping.cpp) ## Not verified Tests, Windows and Linux behavior, and console behavior were not verified. The description reports native Intel Mac test results; I did not run those checks. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28912:upstream-pr/28912'
git switch 'upstream-pr/28912'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28912'
git switch 'upstream-pr/28912'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28912'
git switch 'upstream-pr/28912'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28912'
git switch 'main'
git merge --squash 'upstream-pr/28912'
git switch 'main'
git merge --ff-only 'upstream-pr/28912'
git switch 'main'
git merge 'upstream-pr/28912'
git push origin 'main'
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!28912
No description provided.