fix(libSceFreeType): copy FT_Get_PS_Font_Value output safely #23127

Merged
plentilha merged 1 commit from upstream-pr/23127 into main 2026-11-27 15:27:07 +00:00
plentilha commented 2026-11-18 19:00:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plentilha on 2026-11-18T19:00:10Z.


What

  • Copy retrieved values and widened FT_Long scalars through GuestCopyOut_nid_no_patch while preserving host errno in FT_Get_PS_Font_Value_nid_postfix, removing unchecked GuestArena::HostWrite / std::memcpy writes and returning -1 on unwritable outputs.
  • Add read-only (static const) and unmapped (0x10) output tests preserving errno in GuestFreeTypePsFontValue.cpp, and record the change in docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md.

Tested

  • guest_freetype_ps_font_value (1/1 passed)
  • tools/guest_pointer_audit.py libSceFreeType (0 findings in src/PsFontValue.cpp)
  • tools/debt_fold.py --check
  • core/libs/tests/test_public_headers.py --audit-only

Checklist

  • Followed repo conventions
  • Verified changes locally
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5382237691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23127). Originally posted by [plentilha](https://github.com/plentilha) on 2026-11-18T19:00:10Z. --- ### What - Copy retrieved values and widened `FT_Long` scalars through `GuestCopyOut_nid_no_patch` while preserving host `errno` in `FT_Get_PS_Font_Value_nid_postfix`, removing unchecked `GuestArena::HostWrite` / `std::memcpy` writes and returning `-1` on unwritable outputs. - Add read-only (`static const`) and unmapped (`0x10`) output tests preserving `errno` in `GuestFreeTypePsFontValue.cpp`, and record the change in `docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md`. ### Tested - `guest_freetype_ps_font_value` (`1/1` passed) - `tools/guest_pointer_audit.py libSceFreeType` (`0` findings in `src/PsFontValue.cpp`) - `tools/debt_fold.py --check` - `core/libs/tests/test_public_headers.py --audit-only` ### Checklist - [x] Followed repo conventions - [x] Verified changes locally - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-18 19:02:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T19:02:50Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 430b458e8d:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_freetype_ps_font_value_tests built cleanly.
  • CTest (guest_freetype_ps_font_value):
    1/1 Test #3684: guest_freetype_ps_font_value .....   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceFreeType/src/PsFontValue.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3684: guest_freetype_ps_font_value .....***Exception: SegFault  0.40 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified GuestCopyOut_nid_no_patch integration in WidenedLongValue and FT_Get_PS_Font_Value_nid_postfix replaces unchecked HostWrite/memcpy with safe write verification
    • Verified host errno preservation across GuestCopyOut_nid_no_patch invocations using savedErrno to ensure callers do not observe unexpected side effects
    • Checked error return value -1 when GuestCopyOut_nid_no_patch fails (e.g. read-only or invalid/unmapped guest address)
    • Verified length bounds and condition checks (length > 0 && length <= required) before copying native buffer in FT_Get_PS_Font_Value_nid_postfix
    • Verified LP64 vs LLP64 handling where sizeof(FT_Long) != sizeof(int64_t) widens FT_Long to 64-bit scalar before copying out
    • Verified AGENTS.md conventions: no comments in source code, debt fragment created under docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md
    • Verified unit tests in GuestFreeTypePsFontValue.cpp rigorously assert -1 return, unmodified destination buffer, and preserved errno for unwritable memory

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5963183015 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23127#pullrequestreview-5963183015). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T19:02:50Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `430b458e8d`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_freetype_ps_font_value_tests` built cleanly. - **CTest** (`guest_freetype_ps_font_value`): ``` 1/1 Test #3684: guest_freetype_ps_font_value ..... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceFreeType/src/PsFontValue.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3684: guest_freetype_ps_font_value .....***Exception: SegFault 0.40 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified GuestCopyOut_nid_no_patch integration in WidenedLongValue and FT_Get_PS_Font_Value_nid_postfix replaces unchecked HostWrite/memcpy with safe write verification - Verified host errno preservation across GuestCopyOut_nid_no_patch invocations using savedErrno to ensure callers do not observe unexpected side effects - Checked error return value -1 when GuestCopyOut_nid_no_patch fails (e.g. read-only or invalid/unmapped guest address) - Verified length bounds and condition checks (length > 0 && length <= required) before copying native buffer in FT_Get_PS_Font_Value_nid_postfix - Verified LP64 vs LLP64 handling where sizeof(FT_Long) != sizeof(int64_t) widens FT_Long to 64-bit scalar before copying out - Verified AGENTS.md conventions: no comments in source code, debt fragment created under docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md - Verified unit tests in GuestFreeTypePsFontValue.cpp rigorously assert -1 return, unmodified destination buffer, and preserved errno for unwritable memory Looks Good To Me
MarcZX10 commented 2026-11-23 01:29:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:29:50Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the prepared description reports successful tests, but I did not run them.

What I ran

Reviewed head 430b458e8d8275f128737ecd60d5deee4e82fa9d using repo_read.py reader access. No tests or prechecks were run.

Results

Check Result Note
Changed code review passed All three changed files read
Tests and prechecks not run Results in the PR description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run the reported guest_freetype_ps_font_value, pointer audit, debt check, or public-header audit. Reviewed files: core/libs/prx/libSceFreeType/src/PsFontValue.cpp, core/libs/tests/GuestFreeTypePsFontValue.cpp, and docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md. The review listing showed all three changed files included; no changed files were excluded. Other repository files were not read, so their behavior is not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015635147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23127#pullrequestreview-6015635147). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T01:29:50Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the prepared description reports successful tests, but I did not run them. ## What I ran Reviewed head `430b458e8d8275f128737ecd60d5deee4e82fa9d` using `repo_read.py` reader access. No tests or prechecks were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files read | | Tests and prechecks | not run | Results in the PR description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not run the reported `guest_freetype_ps_font_value`, pointer audit, debt check, or public-header audit. Reviewed files: `core/libs/prx/libSceFreeType/src/PsFontValue.cpp`, `core/libs/tests/GuestFreeTypePsFontValue.cpp`, and `docs/dev/debt/changes/fix-freetype-ps-value-guest-copy.md`. The review listing showed all three changed files included; no changed files were excluded. Other repository files were not read, so their behavior is not verified. ## To get this to a good state Nothing is required.
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!23127
No description provided.