Fixed memory corruption with invalid pixel values.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 23:56:23 -0800
changeset 5436 29977c050731
parent 5435 3de226f0cc06
child 5437 ce10653e370c
Fixed memory corruption with invalid pixel values.
src/video/SDL_pixels.c
--- a/src/video/SDL_pixels.c	Sun Mar 06 23:54:50 2011 -0800
+++ b/src/video/SDL_pixels.c	Sun Mar 06 23:56:23 2011 -0800
@@ -768,9 +768,13 @@
         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 @@
             *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;
+        }
     }
 }