SDL: surface: cannot set a palette to a non-indexed surface (f00b0)

From f00b0291b3fcc6835037a3a17aa4ef81199c0596 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 15 May 2026 03:47:28 +0200
Subject: [PATCH] surface: cannot set a palette to a non-indexed surface

This fixes a UBSAN warning later in this function where it calculates
(1 << SDL_BITSPERPIXEL(surface->format)). The bpp might be >= 32 and
out of range for a bit shift.

(cherry picked from commit d5af35e3fbb5bb6555ed00e69740d52af2a4e877)
---
 src/video/SDL_surface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 8164f76fbc65a..03589321b791e 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -423,7 +423,7 @@ SDL_Palette *SDL_CreateSurfacePalette(SDL_Surface *surface)
 
 bool SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
 {
-    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
+    CHECK_PARAM(!SDL_SurfaceValid(surface) || !SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
         return SDL_InvalidParamError("surface");
     }