Blame SOURCES/0009-CVE-2019-7635-Reject-BMP-images-with-pixel-colors-ou.patch

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