From 0af153efb465ab7ea2ea7565d7e6d5c041928c06 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 29 Mar 2014 19:38:54 -0700 Subject: [PATCH] Avoid a crash with a huge user memory font size. Fixes tests. --- Core/HLE/sceFont.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index d9d7bb9e54..e5b10b689d 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -800,6 +800,13 @@ u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontAddrPtr, u32 memoryFontLe DEBUG_LOG(SCEFONT, "sceFontOpenUserMemory(%08x, %08x, %08x, %08x)", libHandle, memoryFontAddrPtr, memoryFontLength, errorCodePtr); const u8 *fontData = Memory::GetPointer(memoryFontAddrPtr); + // Games are able to overstate the size of a font. Let's avoid crashing when we memcpy() it. + // Unsigned 0xFFFFFFFF is treated as max, but that's impossible, so let's clamp to 64MB. + if (memoryFontLength > 0x03FFFFFF) + memoryFontLength = 0x03FFFFFF; + while (!Memory::IsValidAddress(memoryFontAddrPtr + memoryFontLength - 1)) { + --memoryFontLength; + } Font *f = new Font(fontData, memoryFontLength); LoadedFont *font = fontLib->OpenFont(f, FONT_OPEN_USERBUFFER, *errorCode); if (font) {