From ab17d668843a5807215e7b0f95eb0e8cc1b603e5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 7 Sep 2025 12:55:33 -0700 Subject: [PATCH] Make sure the surface used for a software renderer is a valid format Fixes https://github.com/libsdl-org/SDL/issues/13323 --- src/render/software/SDL_render_sw.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 3a4d3c6877..fc5d4609c3 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -1125,6 +1125,11 @@ bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, S return SDL_InvalidParamError("surface"); } + if (SDL_BITSPERPIXEL(surface->format) < 8 || + SDL_BITSPERPIXEL(surface->format) > 32) { + return SDL_SetError("Unsupported surface format"); + } + renderer->software = true; data = (SW_RenderData *)SDL_calloc(1, sizeof(*data));