From ca4a0a848a1fc2896236a49f3e8f046eef73cff1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:02:28 -0700 Subject: [PATCH] Font: Fix bad memory read on invalid font data. --- Core/Font/PGF.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 20315f4c01..a01b47225c 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -679,6 +679,10 @@ void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, in } static const u8 fontPixelSizeInBytes[] = { 0, 0, 1, 3, 4 }; // 0 means 2 pixels per byte + if (pixelformat < 0 || pixelformat > PSP_FONT_PIXELFORMAT_32) { + ERROR_LOG_REPORT_ONCE(pfgbadformat, SCEFONT, "Invalid image format in image: %d", (int)pixelformat); + return; + } int pixelBytes = fontPixelSizeInBytes[pixelformat]; int bufMaxWidth = (pixelBytes == 0 ? bpl * 2 : bpl / pixelBytes); if (x >= bufMaxWidth) {