Blame SOURCES/SDL-1.2.15-CVE-2019-7638-CVE-2019-7636-Refuse-loading-BMP-image.patch

8d63ce
From 28b1433b4bd7982524f2418420e8cc01786df5c4 Mon Sep 17 00:00:00 2001
8d63ce
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
8d63ce
Date: Fri, 15 Feb 2019 16:52:27 +0100
8d63ce
Subject: [PATCH] CVE-2019-7638, CVE-2019-7636: Refuse loading BMP images with
8d63ce
 too high number of colors
8d63ce
MIME-Version: 1.0
8d63ce
Content-Type: text/plain; charset=UTF-8
8d63ce
Content-Transfer-Encoding: 8bit
8d63ce
8d63ce
If a BMP file that defines more colors than can fit into
8d63ce
a palette of color depth defined in the same BMP file is loaded by
8d63ce
SDL_LoadBMP_RW() function, invalid number of colors is set into
8d63ce
resulting SDL surface.
8d63ce
8d63ce
Then if the SDL surface is passed to SDL_DisplayFormat() function to
8d63ce
convert the surface format into a native video format, a buffer
8d63ce
overread will happen in Map1to1() or Map1toN() function
8d63ce
(CVE-2019-7638). (The choice of the mapping function depends on
8d63ce
a actual video hardware.)
8d63ce
8d63ce
In addition SDL_GetRGB() called indirectly from SDL_DisplayFormat()
8d63ce
performs the same buffer overread (CVE-2019-7636).
8d63ce
8d63ce
There is also probably a buffer overwrite when the SDL_LoadBMP_RW()
8d63ce
loads colors from a file.
8d63ce
8d63ce
This patch fixes it by refusing loading such badly damaged BMP files.
8d63ce
8d63ce
CVE-2019-7638
8d63ce
https://bugzilla.libsdl.org/show_bug.cgi?id=4500
8d63ce
CVE-2019-7636
8d63ce
https://bugzilla.libsdl.org/show_bug.cgi?id=4499
8d63ce
8d63ce
Signed-off-by: Petr Písař <ppisar@redhat.com>
8d63ce
---
8d63ce
 src/video/SDL_bmp.c | 4 ++++
8d63ce
 1 file changed, 4 insertions(+)
8d63ce
8d63ce
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
8d63ce
index d56cfd8..3accded 100644
8d63ce
--- a/src/video/SDL_bmp.c
8d63ce
+++ b/src/video/SDL_bmp.c
8d63ce
@@ -233,6 +233,10 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
8d63ce
 	if ( palette ) {
8d63ce
 		if ( biClrUsed == 0 ) {
8d63ce
 			biClrUsed = 1 << biBitCount;
8d63ce
+		} else if ( biClrUsed > (1 << biBitCount) ) {
8d63ce
+			SDL_SetError("BMP file has an invalid number of colors");
8d63ce
+			was_error = SDL_TRUE;
8d63ce
+			goto done;
8d63ce
 		}
8d63ce
 		if ( biSize == 12 ) {
8d63ce
 			for ( i = 0; i < (int)biClrUsed; ++i ) {
8d63ce
-- 
8d63ce
2.20.1
8d63ce