php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #66356
Patch libgd-v2.patch revision 2013-12-28 08:13 UTC by remi@php.net
Patch libgd-v1.patch revision 2013-12-28 08:13 UTC by remi@php.net
Patch bug66356.patch revision 2013-12-28 05:34 UTC by laruence@php.net

Patch libgd-v1.patch for GD related Bug #66356

Patch version 2013-12-28 08:13 UTC

Return to Bug #66356 | Download this patch
Patch Revisions:

Developer: remi@php.net

diff -up ../ext/gd/libgd/gd_crop.c.old ../ext/gd/libgd/gd_crop.c
--- ../ext/gd/libgd/gd_crop.c.old	2013-12-28 08:43:50.090862436 +0100
+++ ../ext/gd/libgd/gd_crop.c	2013-12-28 09:11:06.076956583 +0100
@@ -44,6 +44,13 @@ gdImagePtr gdImageCrop(gdImagePtr src, c
 {
 	gdImagePtr dst;
 
+	/* check position in the src image */
+	if (crop->x < 0 || crop->width<0 || crop->x>=src->sx
+		|| crop->y<0 || crop->height<0 || crop->y>=src->sy) {
+		return NULL;
+	}
+
+	/* allocate the requested size (could be only partially filled) */
 	if (src->trueColor) {
 		dst = gdImageCreateTrueColor(crop->width, crop->height);
 		gdImageSaveAlpha(dst, 1);
@@ -53,12 +60,14 @@ gdImagePtr gdImageCrop(gdImagePtr src, c
 	}
 	dst->transparent = src->transparent;
 
-	if (src->sx < (crop->x + crop->width -1)) {
-		crop->width = src->sx - crop->x + 1;
+	/* reduce size if needed */
+	if ((src->sx - crop->width) < crop->x) {
+		crop->width = src->sx - crop->x;
 	}
-	if (src->sy < (crop->y + crop->height -1)) {
-		crop->height = src->sy - crop->y + 1;
+	if ((src->sy - crop->height) < crop->y) {
+		crop->height = src->sy - crop->y;
 	}
+
 #if 0
 printf("rect->x: %i\nrect->y: %i\nrect->width: %i\nrect->height: %i\n", crop->x, crop->y, crop->width, crop->height);
 #endif
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC