Skip to content

fix(libSceFreeTypeOt): validate and safely copy error codes in ft_mem helpers - #22160

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:fix/libSceFreeTypeOt-memory-error-copyout
Dec 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:fix/libSceFreeTypeOt-memory-error-copyout

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Wrap GuestWritable_nid_no_patch inside RequireWritable (core/libs/prx/libSceFreeTypeOt/src/Memory.cpp) with GuestArena::HostWrite and preserve caller errno before calling NotImplementedAt_nid_no_patch so write-watched error outputs succeed cleanly.
  • Link guest_freetype_ot_memory_tests with libc across all platforms and upgrade GuestPointers() in core/libs/tests/GuestFreeTypeOtMemory.cpp with null-error refusal assertions, armed GuestArena write-watched error pointer tests (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification) across ft_mem_qalloc, ft_mem_alloc, ft_mem_qrealloc, ft_mem_realloc, ft_mem_dup, and ft_mem_strdup, plus 0x02 read-only arena error refusal checks.
  • Record technical debt in docs/dev/debt/changes/fix-libSceFreeTypeOt-memory-error-copyout.md.

Tested

  • Linux x86_64 Release RAM-disk build in /tmp/anyps5_verify_build, rebased onto origin/main (5f04682cef, PR head 0fbe03fbf1):
    • ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^guest_freetype_ot_memory$": 1/1 Passed.
  • python3 tools/debt_fold.py --check and python3 tools/check_conventions.py --base origin/main: Passed cleanly.

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: none
  • 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 a8f8d44529:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_freetype_ot_memory_tests built cleanly.
  • CTest (guest_freetype_ot_memory):
    1/1 Test #3665: guest_freetype_ot_memory .........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceFreeTypeOt/src/Memory.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3665: guest_freetype_ot_memory .........***Exception: SegFault  0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified Memory.cpp:24,38,52,71,88 null/writable validation on error pointer via GuestWritable_nid_no_patch and safe copy out via GuestCopyOut_nid_no_patch across ft_mem_qalloc, ft_mem_alloc, ft_mem_qrealloc, ft_mem_realloc, and ft_mem_dup.
    • Checked ft_mem_alloc, ft_mem_realloc, and ft_mem_dup nested calls: they delegate with internal error variable (&result) which is a valid stack pointer, ensuring nested GuestWritable checks succeed before outer GuestCopyOut.
    • Verified error codes InvalidArgument (0x06), ArrayTooLarge (0x0A), and OutOfMemory (0x40) against FreeType/libSceFreeTypeOt specifications.
    • Audited LP64/LLP64 portability and 64-bit integer sizing across size conversions and arithmetic.
    • Confirmed docs/dev/debt/changes/ fragment formatting and AGENTS.md compliance (no disallowed comments, valid fragment location).
    • Confirmed GuestFreeTypeOtMemory.cpp tests properly exercise nullptr and invalid guest address (0x10) error paths across modified helpers.

Looks Good To Me

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 17, 2026
@Kikoarl
Kikoarl force-pushed the fix/libSceFreeTypeOt-memory-error-copyout branch 2 times, most recently from 4ac5d55 to 6a640e6 Compare November 17, 2026 12:21
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 17, 2026
@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 6a640e6100, merged alone into main 56c87adbdc (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. Microsoft Defender on this machine quarantines 34 AGC test executables as Trojan:Win64/ShellCode.MKA!MTB when they are linked (the case docs/dev/BUILD.md describes), so their objcopy step fails on both trees and those tests do not run here. This PR adds no other build failure.

guest_freetype_ot_memory, the test this PR adds or extends, passes 3 of 3 runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 6a640e6100, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#16191, #16207, #17573, #18945, #20978, #21054, #22002, #22003, #22042, #22078, #22822, #24354, #24484, #12860, #18915, #19999, #22890, #22891, #23488, #23751, #24051, #24578, #14506, #19462, #22206, #22291, #22627, #24048, #24424). 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_freetype_ot_memory (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 (6526 tests) on the RTX 3080 has 15 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: #12860 (guest_user_service_account_name_limits, guest_user_service_age_level_guest_bounds, guest_user_service_initial_user_bounds, guest_user_service_kratos), #22891 (nkwebkit_securityorigin), #18915 (public_headers); 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): guest_apr_read_longeof, guest_filesystem, guest_kernel_rename, guest_windows_directory_link_types, tools_patch_advisor_json, tools_suggest_patches. The 2125 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

The reviewed change adds null error pointer coverage; code paths validate writable error storage before allocation and copy results out safely.

What I ran

Read the prepared diff at head 6a640e610031717b9be4bbaad3bbf1c78684c278. No commands or tests were run; the test commands in the PR description are author-reported.

Results

Check Result Note
Changed code review passed Both changed files read
Tests not run Author reports targeted test and conventions check
Console behavior not run Not measured per change note

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run. Repository files read: core/libs/tests/GuestFreeTypeOtMemory.cpp, docs/dev/debt/changes/fix-libSceFreeTypeOt-memory-error-copyout.md, and core/libs/prx/libSceFreeTypeOt/src/Memory.cpp. All changed files listed in the manifest were read; no files were excluded.

To get this to a good state

Nothing is required.

@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main and pushed 61472aeef7 wrapping RequireWritable in GuestArena::HostWrite (preserving errno), adding write-watched error pointer test coverage across ft_mem_qalloc/ft_mem_alloc/ft_mem_qrealloc/ft_mem_realloc/ft_mem_dup/ft_mem_strdup in GuestFreeTypeOtMemory.cpp (with libc linked in guest_freetype_ot_memory_tests), and adding Closes when: / Labels: metadata to the debt fragment.

@Kikoarl
Kikoarl force-pushed the fix/libSceFreeTypeOt-memory-error-copyout branch from 6a640e6 to 61472ae Compare November 24, 2026 18:20
@Kikoarl
Kikoarl force-pushed the fix/libSceFreeTypeOt-memory-error-copyout branch from 61472ae to 0fbe03f Compare November 24, 2026 19:45
@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto origin/main (5f04682cef) as 0fbe03fbf1: upgraded GuestFreeTypeOtMemory.cpp to use armed GuestArena write-watched pages (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification) and GuestArenaSetProtection 0x02 read-only arena error refusal checks. Verified 1/1 guest_freetype_ot_memory plus debt_fold.py --check and check_conventions.py.

@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 points below are optional.

What I ran

Reviewed head 0fbe03fbf14a1f4067b737b2a9859035d5c0b2a8 using the prepared diff and repo_read.py for targeted source context. No build or tests were run.

Results

Check Result Note
Diff and changed files passed All four changed files were read.
Build and tests not run Only the author-reported Linux run is described.

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported CTest, debt-fold, and convention checks were not independently run. Windows and console behavior were not verified. The review folder’s files.json was unavailable; the manifest lists four changed files and all four were included and read. No excluded changed files were listed in the manifest.

To get this to a good state

Nothing is required.

@ycbuzi

ycbuzi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Tested 0fbe03fbf1 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 6957; 99% tests passed, 3 tests failed out of 6957. 3 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 6957; 100% tests passed, 0 tests failed out of 6957. run

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

@github-actions github-actions Bot added the build label Nov 30, 2026
@oneandonlydean
oneandonlydean merged commit 91f7d97 into boykopovar:main Dec 3, 2026
14 checks passed
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.

7 participants