fix(libSceFont): accept overlapping render surface rows #8250

Merged
vittoriosalvadore merged 4 commits from upstream-pr/8250 into main 2026-11-01 14:21:46 +00:00
vittoriosalvadore commented 2026-10-20 07:01:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by vittoriosalvadore on 2026-10-20T07:01:38Z.


What

Accept a zero row stride and preserve short positive strides in Font character rendering. Rows may overlap: for positive dimensions their address range is (height - 1) * stride + width * pixelSize, rather than height * stride. An allocation covering that range is sufficient; the API has no allocation length to validate the caller's actual storage. Clipping by surface dimensions and scissor keeps raster writes inside it.

Remove the earlier short-stride rejection and keep main's style-frame/baseline error precedence. Zero width or height retains main's successful metrics-only result, an empty update rectangle and no pixel writes. Negative strides still return SCE_FONT_ERROR_NO_SUPPORT_SURFACE; the difference from the measured module is explicit in technical debt.

Source: BunnyFl's native x86-64 execution of firmware 13.42 Font/FontFt modules and the collaborator's requested correction. This is a published firmware-module harness result, not our own measurement or a console-hardware run. The reported four-byte surface metadata with one-byte coverage writes remains an unresolved format difference; this patch preserves the existing host four-byte raster and records that gap.

Tested

Windows x86-64, WinLibs GCC 15.2.0 r7 (UCRT/POSIX), CMake 4.3.1 and Ninja 1.13.2; root Release configuration, BUILD_TESTING=ON, relinker-only OFF, system dependencies OFF, pinned bundled submodules. Final head 6b6a14635c38229ac220ea51a2b2b7a8d96458c8, based on main f7f03daf52f11191174b1be089a56e268390a707.

  • Full Windows library/relinker build passed: cmake --build build --parallel 3 --target libs relinker, plus all focused Font test targets.
  • All 17 focused Font/FreeType CTest entries pass with zero failures and zero skips, before and after both negative controls and on the final merged head. Command: ctest --test-dir build -R '^(font_render_surface|guest_font.*|guest_system_font|font_face_lifetime.*|guest_freetype)$' -V --timeout 30 --parallel 2.
  • Negative control 1: keep the regression and restore only main's Layout.cpp. It fails at stride 0 with 0x80460050. Negative control 2: reinsert only the old early stride guards into the current Render.cpp. It fails in the mixed-invalid style-frame case by throwing instead of retaining the earlier error. Restore committed production sources, rebuild and rerun all 17: pass, zero skips. The production baseline used for these controls is byte-identical in the final main snapshot.
  • Source audit: 5074 tracked files match Git after normalizing line endings; all five changed blob SHA-256 hashes match the compiled tree. Header declaration audit passes for 373 libraries / 14255 exports. Conventions and whitespace checks pass. Fresh independent Astra (gpt-6-astra, reasoning high) final review completed before push.

The regression uses an asymmetric generated TrueType glyph with the real Font/FontFt/FreeType libraries. It compares the complete buffer with a wide-stride reference projected into overlapping rows in drawing order, including zero coverage inside the update rectangle. Guards surround the declared extent. Coverage includes all three character-rendering exports; strides 0, 1, 16, 64, 130, exact, padded and row-size-minus-one; one- and four-byte host pixels; scissor; 0x00/0xEE initial buffers; height 1; zero width/height; invalid descriptors; mixed-invalid errors and a missing driver with an active style frame followed immediately by a valid rendering.

The one-byte address rule is checked against the formula reported by BunnyFl. The fixture is not their DFHEI5-SONY2022.ttf, so it does not claim to reproduce that font's 309 changed bytes. Four-byte cases verify the current host raster's addressing and extent, not equivalence with the reported firmware raster.

pr_overlap examined 1490 open PRs and found no confirmed overlap. Its only uncompleted shared-file comparison was #12757's Font debt file; its complete diff was reviewed manually: it adds GetLibrary/SetFontsOpenMode test/debt entries, not surface rendering or this regression. No dependency is required. The collaborator's existing branch merge is preserved in history.

No title, proprietary font, console-hardware run, Linux/macOS execution of this revision, GPU execution or full repository CTest run is claimed. Full upstream Linux/Windows CI requires a maintainer dispatch under CONTRIBUTING.md.

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4932210338 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8250). Originally posted by [vittoriosalvadore](https://github.com/vittoriosalvadore) on 2026-10-20T07:01:38Z. --- ### What Accept a zero row stride and preserve short positive strides in Font character rendering. Rows may overlap: for positive dimensions their address range is `(height - 1) * stride + width * pixelSize`, rather than `height * stride`. An allocation covering that range is sufficient; the API has no allocation length to validate the caller's actual storage. Clipping by surface dimensions and scissor keeps raster writes inside it. Remove the earlier short-stride rejection and keep main's style-frame/baseline error precedence. Zero width or height retains main's successful metrics-only result, an empty update rectangle and no pixel writes. Negative strides still return `SCE_FONT_ERROR_NO_SUPPORT_SURFACE`; the difference from the measured module is explicit in technical debt. Source: [BunnyFl's native x86-64 execution of firmware 13.42 Font/FontFt modules](https://github.com/boykopovar/AnyPS5/pull/8250#issuecomment-6417381846) and [the collaborator's requested correction](https://github.com/boykopovar/AnyPS5/pull/8250#issuecomment-6418847368). This is a published firmware-module harness result, not our own measurement or a console-hardware run. The reported four-byte surface metadata with one-byte coverage writes remains an unresolved format difference; this patch preserves the existing host four-byte raster and records that gap. ### Tested Windows x86-64, WinLibs GCC 15.2.0 r7 (UCRT/POSIX), CMake 4.3.1 and Ninja 1.13.2; root Release configuration, BUILD_TESTING=ON, relinker-only OFF, system dependencies OFF, pinned bundled submodules. Final head `6b6a14635c38229ac220ea51a2b2b7a8d96458c8`, based on main `f7f03daf52f11191174b1be089a56e268390a707`. - Full Windows library/relinker build passed: `cmake --build build --parallel 3 --target libs relinker`, plus all focused Font test targets. - All 17 focused Font/FreeType CTest entries pass with zero failures and zero skips, before and after both negative controls and on the final merged head. Command: `ctest --test-dir build -R '^(font_render_surface|guest_font.*|guest_system_font|font_face_lifetime.*|guest_freetype)$' -V --timeout 30 --parallel 2`. - Negative control 1: keep the regression and restore only main's Layout.cpp. It fails at stride 0 with `0x80460050`. Negative control 2: reinsert only the old early stride guards into the current Render.cpp. It fails in the mixed-invalid style-frame case by throwing instead of retaining the earlier error. Restore committed production sources, rebuild and rerun all 17: pass, zero skips. The production baseline used for these controls is byte-identical in the final main snapshot. - Source audit: 5074 tracked files match Git after normalizing line endings; all five changed blob SHA-256 hashes match the compiled tree. Header declaration audit passes for 373 libraries / 14255 exports. Conventions and whitespace checks pass. Fresh independent Astra (`gpt-6-astra`, reasoning high) final review completed before push. The regression uses an asymmetric generated TrueType glyph with the real Font/FontFt/FreeType libraries. It compares the complete buffer with a wide-stride reference projected into overlapping rows in drawing order, including zero coverage inside the update rectangle. Guards surround the declared extent. Coverage includes all three character-rendering exports; strides 0, 1, 16, 64, 130, exact, padded and row-size-minus-one; one- and four-byte host pixels; scissor; 0x00/0xEE initial buffers; height 1; zero width/height; invalid descriptors; mixed-invalid errors and a missing driver with an active style frame followed immediately by a valid rendering. The one-byte address rule is checked against the formula reported by BunnyFl. The fixture is not their DFHEI5-SONY2022.ttf, so it does not claim to reproduce that font's 309 changed bytes. Four-byte cases verify the current host raster's addressing and extent, not equivalence with the reported firmware raster. `pr_overlap` examined 1490 open PRs and found no confirmed overlap. Its only uncompleted shared-file comparison was #12757's Font debt file; its complete diff was reviewed manually: it adds GetLibrary/SetFontsOpenMode test/debt entries, not surface rendering or this regression. No dependency is required. The collaborator's existing branch merge is preserved in history. No title, proprietary font, console-hardware run, Linux/macOS execution of this revision, GPU execution or full repository CTest run is claimed. Full upstream Linux/Windows CI requires a maintainer dispatch under CONTRIBUTING.md. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
vittoriosalvadore commented 2026-10-22 05:41:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by vittoriosalvadore on 2026-10-22T05:41:33Z.


Thank you. Rebased #8250 on main and resolved the documentation conflict. All seven focused Font tests pass with zero skips; the full Windows library/relinker build and negative control also pass. A fresh Astra high review found no issues. The branch is ready for full upstream CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333662171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8250#issuecomment-6333662171). Originally posted by [vittoriosalvadore](https://github.com/vittoriosalvadore) on 2026-10-22T05:41:33Z. --- Thank you. Rebased [#8250](https://github.com/boykopovar/AnyPS5/pull/8250) on main and resolved the documentation conflict. All seven focused Font tests pass with zero skips; the full Windows library/relinker build and negative control also pass. A fresh Astra high review found no issues. The branch is ready for full upstream CI.
harisibrar1 commented 2026-10-24 13:48:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:48:41Z.

Review: COMMENTED


Checked against main 522e32e3b6 and core/libs/prx/libSceFont/src/Layout.cpp / Render.cpp on main:

  • Besides the debt-file conflict and the #9992 test row already mentioned, Render.cpp merges cleanly, and the stride guard's early returns (width/height <= 0, stride <= 0) agree with main's zero-extent rule.
  • A question on the premise: the API doesn't pass a buffer size, and main writes at buffer + row*widthByte + column*bpp, clipped to width/height (Layout.cpp:164-188). With height 1, width 80 and stride 16, main only touches bytes 0-79, which is in bounds for an 80-byte buffer, yet this PR throws. With more rows, a short stride makes rows overlap but stays within (h-1)*stride + w*bpp. The "wrote beyond buffer" result comes from the test treating the buffer as stride*height. Could the description and debt entry describe this as a guard for an unverified case rather than an overflow fix? Has any title been seen passing such a surface?
  • Small one: in sceFontRenderCharGlyphImage the guard now runs before the style-frame/baseline errors (preRc), so that error code is replaced by a throw when both conditions hold.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638472370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8250#pullrequestreview-5638472370). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T13:48:41Z. **Review:** COMMENTED --- Checked against main 522e32e3b6 and core/libs/prx/libSceFont/src/Layout.cpp / Render.cpp on main: - Besides the debt-file conflict and the #9992 test row already mentioned, Render.cpp merges cleanly, and the stride guard's early returns (width/height <= 0, stride <= 0) agree with main's zero-extent rule. - A question on the premise: the API doesn't pass a buffer size, and main writes at `buffer + row*widthByte + column*bpp`, clipped to width/height (Layout.cpp:164-188). With height 1, width 80 and stride 16, main only touches bytes 0-79, which is in bounds for an 80-byte buffer, yet this PR throws. With more rows, a short stride makes rows overlap but stays within `(h-1)*stride + w*bpp`. The "wrote beyond buffer" result comes from the test treating the buffer as `stride*height`. Could the description and debt entry describe this as a guard for an unverified case rather than an overflow fix? Has any title been seen passing such a surface? - Small one: in `sceFontRenderCharGlyphImage` the guard now runs before the style-frame/baseline errors (preRc), so that error code is replaced by a throw when both conditions hold. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!8250
No description provided.