af9dc8
Fix for CVE-2017-10168
af9dc8
Backported for 5.4 without test and binary patch
af9dc8
af9dc8
af9dc8
From f1b2afc9d9e77edf41804f5dfc4e2069d8a12975 Mon Sep 17 00:00:00 2001
af9dc8
From: "Christoph M. Becker" <cmbecker69@gmx.de>
af9dc8
Date: Tue, 16 Aug 2016 18:23:36 +0200
af9dc8
Subject: [PATCH] Fix #73868: DOS vulnerability in gdImageCreateFromGd2Ctx()
af9dc8
af9dc8
We must not pretend that there are image data if there are none. Instead
af9dc8
we fail reading the image file gracefully.
af9dc8
af9dc8
(cherry picked from commit cdb648dc4115ce0722f3cc75e6a65115fc0e56ab)
af9dc8
---
af9dc8
 ext/gd/libgd/gd_gd2.c      |   8 ++++++--
af9dc8
 ext/gd/tests/bug73868.gd2  | Bin 0 -> 1050 bytes
af9dc8
 ext/gd/tests/bug73868.phpt |  18 ++++++++++++++++++
af9dc8
 3 files changed, 24 insertions(+), 2 deletions(-)
af9dc8
 create mode 100644 ext/gd/tests/bug73868.gd2
af9dc8
 create mode 100644 ext/gd/tests/bug73868.phpt
af9dc8
af9dc8
diff --git a/ext/gd/libgd/gd_gd2.c b/ext/gd/libgd/gd_gd2.c
af9dc8
index d06f328..196b785 100644
af9dc8
--- a/ext/gd/libgd/gd_gd2.c
af9dc8
+++ b/ext/gd/libgd/gd_gd2.c
af9dc8
@@ -334,12 +334,16 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
af9dc8
 					for (x = xlo; x < xhi; x++) {
af9dc8
 						if (im->trueColor) {
af9dc8
 							if (!gdGetInt(&im->tpixels[y][x], in)) {
af9dc8
-								im->tpixels[y][x] = 0;
af9dc8
+								php_gd_error("gd2: EOF while reading\n");
af9dc8
+								gdImageDestroy(im);
af9dc8
+								return NULL;
af9dc8
 							}
af9dc8
 						} else {
af9dc8
 							int ch;
af9dc8
 							if (!gdGetByte(&ch, in)) {
af9dc8
-								ch = 0;
af9dc8
+								php_gd_error("gd2: EOF while reading\n");
af9dc8
+								gdImageDestroy(im);
af9dc8
+								return NULL;
af9dc8
 							}
af9dc8
 							im->pixels[y][x] = ch;
af9dc8
 						}
af9dc8
-- 
af9dc8
2.1.4
af9dc8