Blame SOURCES/0001-cursor-Fix-heap-overflows-when-parsing-malicious-fil.patch

3949fc
From 5d201df72f3d4f4cb8b8f75f980169b03507da38 Mon Sep 17 00:00:00 2001
3949fc
From: Tobias Stoeckmann <tobias@stoeckmann.org>
3949fc
Date: Tue, 28 Nov 2017 21:38:07 +0100
3949fc
Subject: [PATCH] cursor: Fix heap overflows when parsing malicious files.
3949fc
3949fc
It is possible to trigger heap overflows due to an integer overflow
3949fc
while parsing images.
3949fc
3949fc
The integer overflow occurs because the chosen limit 0x10000 for
3949fc
dimensions is too large for 32 bit systems, because each pixel takes
3949fc
4 bytes. Properly chosen values allow an overflow which in turn will
3949fc
lead to less allocated memory than needed for subsequent reads.
3949fc
3949fc
See also: https://cgit.freedesktop.org/xorg/lib/libXcursor/commit/?id=4794b5dd34688158fb51a2943032569d3780c4b8
3949fc
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=103961
3949fc
3949fc
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
3949fc
[Pekka: add link to the corresponding libXcursor commit]
3949fc
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
3949fc
---
3949fc
 cursor/xcursor.c | 8 +++++++-
3949fc
 1 file changed, 7 insertions(+), 1 deletion(-)
3949fc
3949fc
diff --git a/cursor/xcursor.c b/cursor/xcursor.c
3949fc
index ca41c4a..689c702 100644
3949fc
--- a/cursor/xcursor.c
3949fc
+++ b/cursor/xcursor.c
3949fc
@@ -202,6 +202,11 @@ XcursorImageCreate (int width, int height)
3949fc
 {
3949fc
     XcursorImage    *image;
3949fc
 
3949fc
+    if (width < 0 || height < 0)
3949fc
+       return NULL;
3949fc
+    if (width > XCURSOR_IMAGE_MAX_SIZE || height > XCURSOR_IMAGE_MAX_SIZE)
3949fc
+       return NULL;
3949fc
+
3949fc
     image = malloc (sizeof (XcursorImage) +
3949fc
 		    width * height * sizeof (XcursorPixel));
3949fc
     if (!image)
3949fc
@@ -482,7 +487,8 @@ _XcursorReadImage (XcursorFile		*file,
3949fc
     if (!_XcursorReadUInt (file, &head.delay))
3949fc
 	return NULL;
3949fc
     /* sanity check data */
3949fc
-    if (head.width >= 0x10000 || head.height > 0x10000)
3949fc
+    if (head.width > XCURSOR_IMAGE_MAX_SIZE  ||
3949fc
+	head.height > XCURSOR_IMAGE_MAX_SIZE)
3949fc
 	return NULL;
3949fc
     if (head.width == 0 || head.height == 0)
3949fc
 	return NULL;
3949fc
-- 
3949fc
2.14.3
3949fc