8d9706
From 1423e12e0bcf5cc43804ac5b31156a4acc316ea9 Mon Sep 17 00:00:00 2001
8d9706
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
8d9706
Date: Tue, 11 Jun 2019 06:28:12 -0700
8d9706
Subject: [PATCH 09/11] CVE-2019-7635: Reject BMP images with pixel colors out
8d9706
 the palette If a 1-, 4-, or 8-bit per pixel BMP image declares less used
8d9706
 colors than the palette offers an SDL_Surface with a palette of the indicated
8d9706
 number of used colors is created. If some of the image's pixel refer to a
8d9706
 color number higher then the maximal used colors, a subsequent bliting
8d9706
 operation on the surface will look up a color past a blit map (that is based
8d9706
 on the palette) memory. I.e. passing such SDL_Surface to e.g. an
8d9706
 SDL_DisplayFormat() function will result in a buffer overread in a blit
8d9706
 function.
8d9706
MIME-Version: 1.0
8d9706
Content-Type: text/plain; charset=UTF-8
8d9706
Content-Transfer-Encoding: 8bit
8d9706
8d9706
This patch fixes it by validing each pixel's color to be less than the
8d9706
maximal color number in the palette. A validation failure raises an
8d9706
error from a SDL_LoadBMP_RW() function.
8d9706
8d9706
CVE-2019-7635
8d9706
https://bugzilla.libsdl.org/show_bug.cgi?id=4498
8d9706
8d9706
Signed-off-by: Petr Písař <ppisar@redhat.com>
8d9706
8d9706
--HG--
8d9706
branch : SDL-1.2
8d9706
---
8d9706
 src/video/SDL_bmp.c | 16 ++++++++++++++++
8d9706
 1 file changed, 16 insertions(+)
8d9706
8d9706
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
8d9706
index 1b6e0ed06..c1f1a24f5 100644
8d9706
--- a/src/video/SDL_bmp.c
8d9706
+++ b/src/video/SDL_bmp.c
8d9706
@@ -301,6 +301,12 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
8d9706
 				}
8d9706
 				*(bits+i) = (pixel>>shift);
8d9706
 				pixel <<= ExpandBMP;
8d9706
+				if ( bits[i] >= biClrUsed ) {
8d9706
+					SDL_SetError(
8d9706
+						"A BMP image contains a pixel with a color out of the palette");
8d9706
+					was_error = SDL_TRUE;
8d9706
+					goto done;
8d9706
+				}
8d9706
 			} }
8d9706
 			break;
8d9706
 
8d9706
@@ -311,6 +317,16 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
8d9706
 				was_error = SDL_TRUE;
8d9706
 				goto done;
8d9706
 			}
8d9706
+			if ( 8 == biBitCount && palette && biClrUsed < (1 << biBitCount ) ) {
8d9706
+				for ( i=0; i<surface->w; ++i ) {
8d9706
+					if ( bits[i] >= biClrUsed ) {
8d9706
+						SDL_SetError(
8d9706
+							"A BMP image contains a pixel with a color out of the palette");
8d9706
+						was_error = SDL_TRUE;
8d9706
+						goto done;
8d9706
+					}
8d9706
+				}
8d9706
+			}
8d9706
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
8d9706
 			/* Byte-swap the pixels if needed. Note that the 24bpp
8d9706
 			   case has already been taken care of above. */
8d9706
-- 
8d9706
2.24.1
8d9706