php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #66815
Patch test.patch revision 2014-03-03 16:20 UTC by remi@php.net
Patch 0001-Fix-NULL-deref-in-gdImageCrop.patch revision 2014-03-03 16:19 UTC by remi@php.net
Patch libgd-test.patch revision 2014-03-03 16:13 UTC by remi@php.net
Patch tests.patch revision 2014-03-03 16:10 UTC by remi@php.net

Patch libgd-test.patch for GD related Bug #66815

Patch version 2014-03-03 16:13 UTC

Return to Bug #66815 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: remi@php.net

diff -up ext/gd/libgd/gd_crop.c.orig ext/gd/libgd/gd_crop.c
--- ext/gd/libgd/gd_crop.c.orig	2014-03-03 15:50:53.478394740 +0100
+++ ext/gd/libgd/gd_crop.c	2014-03-03 16:45:54.584277726 +0100
@@ -45,22 +45,20 @@ gdImagePtr gdImageCrop(gdImagePtr src, c
 	gdImagePtr dst;
 	int y;
 
-	/* check size */
-	if (crop->width<=0 || crop->height<=0) {
-		return NULL;
-	}
-
 	/* allocate the requested size (could be only partially filled) */
 	if (src->trueColor) {
 		dst = gdImageCreateTrueColor(crop->width, crop->height);
+		if (dst == NULL) {
+			return NULL;
+		}
 		gdImageSaveAlpha(dst, 1);
 	} else {
 		dst = gdImageCreate(crop->width, crop->height);
+		if (dst == NULL) {
+			return NULL;
+		}
 		gdImagePaletteCopy(dst, src);
 	}
-	if (dst == NULL) {
-		return NULL;
-	}
 	dst->transparent = src->transparent;
 
 	/* check position in the src image */
diff -up ext/gd/tests/bug66356.phpt.orig ext/gd/tests/bug66356.phpt
--- ext/gd/tests/bug66356.phpt.orig	2014-03-03 16:55:47.826375795 +0100
+++ ext/gd/tests/bug66356.phpt	2014-03-03 16:55:57.130408433 +0100
@@ -24,6 +24,8 @@ var_dump(imagecrop($img, array("x" => -2
 // POC #4
 var_dump(imagecrop($img, array("x" => 0x7fffff00, "y" => 0, "width" => 10, "height" => 10)));
 
+// bug 66815
+var_dump(imagecrop($img, array("x" => 0, "y" => 0, "width" => 65535, "height" => 65535)));
 ?>
 --EXPECTF--
 resource(%d) of type (gd)
@@ -35,6 +37,13 @@ Array
     [width] => 10
     [height] => 10
 )
+
+Warning: imagecrop(): gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully
+ in %sbug66356.php on line %d
 bool(false)
 resource(%d) of type (gd)
-resource(%d) of type (gd)
\ Pas de fin de ligne à la fin du fichier
+resource(%d) of type (gd)
+
+Warning: imagecrop(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
+ in %sbug66356.php on line %d
+bool(false)
\ Pas de fin de ligne à la fin du fichier
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Mar 01 20:02:07 2015 UTC