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

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