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