SDL_image: Fixed out of bounds read of invalid XPM file

From 0e1375755a30bd581b9c98e60a59c160349480ef Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 21 Aug 2026 09:38:03 -0700
Subject: [PATCH] Fixed out of bounds read of invalid XPM file

Fixes https://github.com/libsdl-org/SDL_image/issues/753
---
 src/IMG_xpm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/IMG_xpm.c b/src/IMG_xpm.c
index 2f10e5ad5..d07870935 100644
--- a/src/IMG_xpm.c
+++ b/src/IMG_xpm.c
@@ -1086,6 +1086,10 @@ static SDL_Surface *load_xpm(char **xpm, SDL_IOStream *src, bool force_32bit)
             goto done;
 
         p = line + cpp + 1;
+        if (p >= (line + SDL_strlen(line))) {
+            error = "Invalid color specification";
+            goto done;
+        }
 
         /* parse a colour definition */
         for (;;) {