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

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