From 2c461991208c678c444c468509358bf98105b111 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 6 Mar 2011 23:56:23 -0800 Subject: [PATCH] Fixed memory corruption with invalid pixel values. --- src/video/SDL_pixels.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index b31ea4998..e667f0952 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -768,9 +768,13 @@ SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g, v = (pixel & format->Bmask) >> format->Bshift; *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); } else { - *r = format->palette->colors[pixel].r; - *g = format->palette->colors[pixel].g; - *b = format->palette->colors[pixel].b; + if (pixel < format->palette->ncolors) { + *r = format->palette->colors[pixel].r; + *g = format->palette->colors[pixel].g; + *b = format->palette->colors[pixel].b; + } else { + *r = *g = *b = 0; + } } } @@ -802,10 +806,14 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, *a = SDL_ALPHA_OPAQUE; } } else { - *r = format->palette->colors[pixel].r; - *g = format->palette->colors[pixel].g; - *b = format->palette->colors[pixel].b; - *a = SDL_ALPHA_OPAQUE; + if (pixel < format->palette->ncolors) { + *r = format->palette->colors[pixel].r; + *g = format->palette->colors[pixel].g; + *b = format->palette->colors[pixel].b; + *a = SDL_ALPHA_OPAQUE; + } else { + *r = *g = *b = *a = 0; + } } }