Skip to content

fix(libSceFont): check fill plot guest inputs and output - #20340

Merged
oneandonlydean merged 6 commits into
boykopovar:mainfrom
hyvvs:fix/libSceFont-fill-plot-guest-pointers
Nov 17, 2026
Merged

oneandonlydean merged 6 commits into
boykopovar:mainfrom
hyvvs:fix/libSceFont-fill-plot-guest-pointers

Conversation

@hyvvs

@hyvvs hyvvs commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

sceFontGraphicsFillPlotInit dereferenced a guest region through a raw pointer and wrote a 64-byte fill-plot directly into guest memory. Invalid non-null pointers (such as 0x10) crashed the host, including a damaged region pointer on an otherwise valid output.

Read real region descriptors through an errno-preserving checked guest copy. Construct the complete fill-plot locally and write it through CopyOutGuest. For an invalid region, preserve the existing behavior of clearing only the two-byte plot tag, but do so through a checked write with pointer overflow guard. Preserve null region and -1 sentinel region behavior. New inaccessible-pointer error choices are host-safety fallbacks, not a measured PS5 ABI rule.

Tested

  • Production Graphics.cpp linked to checked process_vm_readv/process_vm_writev guest shims under Ubuntu GCC13 ASan/UBSan/LSan: invalid input/output, errno preservation, unchanged non-tag bytes on invalid region, normal region, null region and -1 sentinel all PASS with leak detection.
  • Identical test with unchanged upstream Graphics.cpp FAILS ASan SIGSEGV while writing to 0x10.
  • Existing GuestFontGraphics.cpp regression extended for both bad pointers and untouched fields.
  • WinLibs GCC15 C++20 syntax-only for Graphics.cpp and GuestFontGraphics.cpp PASS.
  • Conventions and git diff --check PASS.
  • Full overlap scan tested 1,525 open PRs with exit 0: no conflicts. Historical authored closed candidate screening and feat(libSceFont): initialize graphics region and fill plot descriptors #9996/feat(libSceFont): build the graphics region and fill descriptors as the console does #9722 checks found no duplicate pointer fix.
  • No full application build, hosted Windows runtime or PS5 hardware testing claimed.

Checklist

  • Based on refreshed upstream main; no current competing PR implements these pointer checks
  • One focused data-validation bug with actual negative-control
  • No code comments or fabricated exports; console uncertainty captured in debt
  • No bundled third-party binaries
  • Depends on: 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 08ad40eb30:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_font_graphics_tests built cleanly.
  • CTest (guest_font_graphics):
    1/1 Test #3281: guest_font_graphics ..............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceFont/src/Graphics.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3281: guest_font_graphics ..............***Exception: SegFault  0.41 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceFont/src/Graphics.cpp (GraphicsFillPlotInit): Verified null/sentinel pointer handling for plot and region, confirming IsObject correctly handles nullptr and ~0ULL sentinels (flags = 2 for null region, flags = 6 for -1 region).
    • core/libs/prx/libSceFont/src/Graphics.cpp (GraphicsFillPlotInit): Verified guest memory safety on invalid region handling; confirmed GuestCopyIn_nid_no_patch checks readability, preserves errno, and conditionally clears tag via CopyOutGuest with pointer overflow check (address > UINTPTR_MAX - tagOffset).
    • core/libs/prx/libSceFont/src/Graphics.cpp (GraphicsFillPlotInit): Verified error precedence and return codes (FONT_GRAPHICS_ERROR_INVALID_FILL_PLOT vs FONT_GRAPHICS_ERROR_INVALID_REGION), confirming unwritable output reports INVALID_FILL_PLOT on both the invalid-region tag-clearing path and the success write-out path.
    • core/libs/prx/libSceFont/src/Graphics.cpp (GraphicsFillPlotInit): Verified output construction in local stack variable value before CopyOutGuest, preventing host SIGSEGV or partial/corrupted memory writes on invalid output pointers.
    • core/libs/tests/GuestFontGraphics.cpp (FillPlots): Verified unit test coverage for bad pointers (0x10), errno preservation, untouched non-tag byte verification (0xa5), and subsequent layout/mapping setter behavior.
    • docs/dev/debt/libSceFont.md: Verified debt documentation accurately records the host-safety fallback policies for inaccessible guest memory in sceFontGraphicsFillPlotInit.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

@hyvvs

hyvvs commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@PrivacyOnion Thank you for reviewing. I corrected the PR checklist to include the required Depends on: none field (the initial hosted conventions failure was limited to the template). The corrected body should be picked up by the newly queued conventions run. The production and regression commit is unchanged and I will distinguish new workflow results from the original failed job.

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

hyvvs commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

The previous conventions failure was from the missing Depends on field; the current PR description now has ### What, ### Tested, ### Checklist and checked Depends on: none / AI-assisted: yes. Since main moved (including #20345), I merged current upstream into this separate branch normally and pushed 3d073ae. GitHub head is mergeable, local conventions/whitespace checks and Windows GCC15 Graphics.cpp plus GuestFontGraphics.cpp syntax pass, and the original source-linked sanitizer negative control is documented. New hosted checks are queued; please re-evaluate against this head. No full project CTest claim.

@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 3d073aec54:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_font_graphics_tests failed to build.
    ftbase.c:(.text+0x1bb7): undefined reference to `FT_Stream_Open'
    ftbase.c:(.text+0x24c7): undefined reference to `FT_Stream_Open'
    ftbase.c:(.text+0x73c8): undefined reference to `FT_Stream_Open'
    ftbase.c:(.text+0x74c8): undefined reference to `FT_Stream_Open'
    ftbase.c:(.text+0x75c8): undefined reference to `FT_Stream_Open'
    /usr/bin/ld: 3rdparty/freetype/libfreetype.a(ftbase.c.o):ftbase.c:(.text+0xe495): more undefined references to `FT_Stream_Open' follow
    ftinit.c:(.text+0x1fc): undefined reference to `FT_New_Memory'
    /usr/bin/ld: ftinit.c:(.text+0x23c): undefined reference to `FT_Done_Memory'
    ftinit.c:(.text+0x276): undefined reference to `FT_Done_Memory'
    collect2: error: ld returned 1 exit status
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

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

@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 reviewed code supports merging, and the checks described by the author are not checks I ran.

What I ran

Reviewed head d4324b9111fdc1923ca7a60d9cf2c16348a0400c. No commands or tests were run. Read description.md, commits.md, manifest.json, diff.patch, README.md, and all three changed files: core/libs/prx/libSceFont/src/Graphics.cpp, core/libs/tests/GuestFontGraphics.cpp, and docs/dev/debt/changes/fix-font-fill-plot-guest.md. No changed files were excluded.

Results

Check Result Note
Changed code review passed Added paths checked against surrounding helpers
Tests in this review not run Author reports targeted tests passed
Build and hardware checks not run Author reports these were not run

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the reported sanitizer tests, syntax checks, or diff checks, and did not verify Windows runtime or PS5 hardware behavior. The claimed overlap and duplicate-fix scans were not verified.

To get this to a good state

Nothing is required.

@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 d4324b9111:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_font_graphics_tests built cleanly.
  • CTest (guest_font_graphics):
    1/1 Test #3285: guest_font_graphics ..............   Passed    0.07 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceFont/src/Graphics.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3285: guest_font_graphics ..............***Exception: SegFault  1.04 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • In core/libs/prx/libSceFont/src/Graphics.cpp (GraphicsFillPlotInit), verified that bad guest region pointers are safely read through GuestCopyIn_nid_no_patch into a local guestRegion copy while preserving errno, preventing host segmentation faults on invalid addresses such as 0x10.
    • Verified that when an input region is invalid or unreadable, GraphicsFillPlotInit clears only plot->tag (offset 24, 2 bytes) via CopyOutGuest with an overflow guard (address > UINTPTR_MAX - tagOffset), returning FONT_GRAPHICS_ERROR_INVALID_REGION (or FONT_GRAPHICS_ERROR_INVALID_FILL_PLOT if plot is unwritable) and leaving non-tag bytes untouched.
    • Verified that null (nullptr, flags = 2) and sentinel ((void*)-1, flags = 6, layout = DefaultLayout) region handling preserves existing Orbis behavior without dereferencing region.
    • Verified that full output construction for valid regions builds local value with correct mapping calculations and stores the caller's guest region pointer before writing through CopyOutGuest(plot, value), returning FONT_GRAPHICS_ERROR_INVALID_FILL_PLOT if output writing fails.
    • In core/libs/tests/GuestFontGraphics.cpp (FillPlots), verified that tests exercise unwritable fill plot (0x10), unreadable region pointer (0x10), errno preservation (errno == 71), and non-tag byte preservation (AllBytes(plot, 0, 24, 0xa5) and AllBytes(plot, 26, 64, 0xa5)).
    • In docs/dev/debt/changes/fix-font-fill-plot-guest.md, verified that the debt fragment adheres to the technical debt format under # libSceFont / ## add Unknown function info with zero disallowed comments in code per AGENTS.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit af1208e into boykopovar:main Nov 17, 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.

4 participants