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

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