From bce7d3ae957db81434e73bd6e817ee76e01d58f9 Mon Sep 17 00:00:00 2001 From: Kikoarl <7354010+Kikoarl@users.noreply.github.com> Date: Tue, 17 Nov 2026 06:15:01 +0100 Subject: [PATCH] fix(libSceFont): safely copy out scaled kerning in sceFontGetRenderScaledKerning --- core/libs/prx/libSceFont/src/Render.cpp | 8 ++++++-- core/libs/tests/GuestFont.cpp | 2 ++ .../fix-libSceFont-getRenderScaledKerning-copyout.md | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 docs/dev/debt/changes/fix-libSceFont-getRenderScaledKerning-copyout.md diff --git a/core/libs/prx/libSceFont/src/Render.cpp b/core/libs/prx/libSceFont/src/Render.cpp index 33ec347c8a24..b279171825eb 100644 --- a/core/libs/prx/libSceFont/src/Render.cpp +++ b/core/libs/prx/libSceFont/src/Render.cpp @@ -316,7 +316,8 @@ int APS5_VABI sceFontGetKerning(FontHandle fontHandle, std::uint32_t preCode, st int APS5_VABI sceFontGetRenderScaledKerning(FontHandle fontHandle, std::uint32_t preCode, std::uint32_t code, FontKerning* kerning) { if (!kerning) return SCE_FONT_ERROR_INVALID_PARAMETER; - *kerning = {}; + FontKerning localKerning{}; + if (!CopyOutGuest(kerning, localKerning)) return SCE_FONT_ERROR_INVALID_PARAMETER; auto* font = GetNativeFont(fontHandle); std::uint32_t fontLock = 0; if (!font || font->magic != HANDLE_MAGIC || !AcquireFontLock(font, fontLock)) return SCE_FONT_ERROR_INVALID_FONT_HANDLE; @@ -331,7 +332,10 @@ int APS5_VABI sceFontGetRenderScaledKerning(FontHandle fontHandle, std::uint32_t float scaleH = 0.0f; rc = StyleStateGetScalePixel(&font->cached_style.state, &scaleW, &scaleH); const FontState* state = TryGetState(fontHandle); - if (rc == SCE_FONT_OK && state) LoadKerning(*state, scaleW, scaleH, preCode, code, kerning); + if (rc == SCE_FONT_OK && state) { + LoadKerning(*state, scaleW, scaleH, preCode, code, &localKerning); + if (!CopyOutGuest(kerning, localKerning)) rc = SCE_FONT_ERROR_INVALID_PARAMETER; + } } ReleaseCachedStyleLock(font, cachedLock); ReleaseFontLock(font, fontLock); diff --git a/core/libs/tests/GuestFont.cpp b/core/libs/tests/GuestFont.cpp index 7b431924dcdd..1eea9edff115 100644 --- a/core/libs/tests/GuestFont.cpp +++ b/core/libs/tests/GuestFont.cpp @@ -1226,6 +1226,8 @@ int main() { kerning = {1.0f, 1.0f, 1.0f, 1.0f}; Require(sceFontGetRenderScaledKerning(font, 'A', 'B', &kerning) == SCE_FONT_OK && KerningIs(kerning, 0.0f)); Require(sceFontGetRenderScaledKerning(font, 'A', 'V', nullptr) == SCE_FONT_ERROR_INVALID_PARAMETER); + errno = EBUSY; + Require(sceFontGetRenderScaledKerning(font, 'A', 'V', reinterpret_cast(std::uintptr_t{0x10})) == SCE_FONT_ERROR_INVALID_PARAMETER && errno == EBUSY); kerning = {1.0f, 1.0f, 1.0f, 1.0f}; Require(sceFontGetRenderScaledKerning(nullptr, 'A', 'V', &kerning) == SCE_FONT_ERROR_INVALID_FONT_HANDLE && KerningIs(kerning, 0.0f)); kerning = {1.0f, 1.0f, 1.0f, 1.0f}; diff --git a/docs/dev/debt/changes/fix-libSceFont-getRenderScaledKerning-copyout.md b/docs/dev/debt/changes/fix-libSceFont-getRenderScaledKerning-copyout.md new file mode 100644 index 000000000000..d29ad21464bd --- /dev/null +++ b/docs/dev/debt/changes/fix-libSceFont-getRenderScaledKerning-copyout.md @@ -0,0 +1,5 @@ +# libSceFont + +## add Functional + +- [sceFontGetRenderScaledKerning](../../../core/libs/prx/libSceFont/src/Render.cpp) (libSceFont) - returning `SCE_FONT_ERROR_INVALID_PARAMETER` for an unwritable `kerning` pointer via `CopyOutGuest` with caller `errno` preserved is a host-safety fallback with console behavior unmeasured. Closes when: measured on hardware. Labels: console, tested.