summaryrefslogtreecommitdiff
path: root/graphics/imlib/patches/patch-an
blob: 7c056e8a577dab34b4b1c9a1afcad1ed3d5288ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$NetBSD: patch-an,v 1.1.2.2 2004/12/13 18:03:27 salo Exp $

--- gdk_imlib/misc.c.orig	2002-03-04 18:06:32.000000000 +0100
+++ gdk_imlib/misc.c	2004-12-10 10:15:22.000000000 +0100
@@ -1355,11 +1355,16 @@
 
 /*
  *	Make sure we don't wrap on our memory allocations
+ *	we check G_MAX_INT/4 because rend.c malloc's w * h * bpp
+ *	+ 3 is safety margin
  */
 
 void *_gdk_malloc_image(unsigned int w, unsigned int h)
 {
-	if( w > 32767 || h > 32767)
+	if (w <= 0 || w > 32767 ||
+	    h <= 0 || h > 32767 ||
+	    h >= (G_MAXINT/4 - 1) / w)
 		return NULL;
-	return malloc(w * h * 3);
+	return malloc(w * h * 3 + 3);
 }
+