af9dc8
Backported from 5.5.37 for 5.4 by Remi Collet
af9dc8
af9dc8
af9dc8
From c395c6e5d7e8df37a21265ff76e48fe75ceb5ae6 Mon Sep 17 00:00:00 2001
af9dc8
From: Stanislav Malyshev <stas@php.net>
af9dc8
Date: Mon, 20 Jun 2016 23:58:26 -0700
af9dc8
Subject: [PATCH] iFixed bug #72446 - Integer Overflow in
af9dc8
 gdImagePaletteToTrueColor() resulting in heap overflow
af9dc8
af9dc8
---
af9dc8
 NEWS              |  2 ++
af9dc8
 ext/gd/libgd/gd.c | 22 +++++++++++++---------
af9dc8
 2 files changed, 15 insertions(+), 9 deletions(-)
af9dc8
af9dc8
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
af9dc8
index 2c63aac..4dad95a 100644
af9dc8
--- a/ext/gd/libgd/gd.c
af9dc8
+++ b/ext/gd/libgd/gd.c
af9dc8
@@ -133,6 +133,10 @@ gdImagePtr gdImageCreate (int sx, int sy)
af9dc8
 		return NULL;
af9dc8
 	}
af9dc8
 
af9dc8
+	if (overflow2(sizeof(unsigned char *), sx)) {
af9dc8
+		return NULL;
af9dc8
+	}
af9dc8
+
af9dc8
 	im = (gdImage *) gdCalloc(1, sizeof(gdImage));
af9dc8
 
af9dc8
 	/* Row-major ever since gd 1.3 */
af9dc8