1 This fixes PHP bug #73159: https://bugs.php.net/bug.php?id=73159
3 Patch lifted from upstream source repository:
5 https://github.com/libgd/libgd/commit/e1f61a4141d2e0937a13b8bfb1992b9f29eb05f5
7 From e1f61a4141d2e0937a13b8bfb1992b9f29eb05f5 Mon Sep 17 00:00:00 2001
8 From: "Christoph M. Becker" <cmbecker69@gmx.de>
9 Date: Mon, 15 Aug 2016 17:49:40 +0200
10 Subject: [PATCH] Fix #289: Passing unrecognized formats to gdImageGd2 results
13 We must not apply the format correction twice for truecolor images.
15 (cherry picked from commit 09090c125658e23a4ae2a2e002646bb7278bd89e)
18 tests/gd2/CMakeLists.txt | 1 +
19 tests/gd2/Makemodule.am | 1 +
20 tests/gd2/bug_289.c | 33 +++++++++++++++++++++++++++++++++
21 4 files changed, 36 insertions(+), 1 deletion(-)
22 create mode 100644 tests/gd2/bug_289.c
24 diff --git a/src/gd_gd2.c b/src/gd_gd2.c
25 index 86c881e..75e5e1f 100644
28 @@ -918,7 +918,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
29 /* Force fmt to a valid value since we don't return anything. */
31 if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
32 - fmt = im->trueColor ? GD2_FMT_TRUECOLOR_COMPRESSED : GD2_FMT_COMPRESSED;
33 + fmt = GD2_FMT_COMPRESSED;
37 diff --git a/tests/gd2/CMakeLists.txt b/tests/gd2/CMakeLists.txt
38 index 8aecacc..3b650ad 100644
39 --- a/tests/gd2/CMakeLists.txt
40 +++ b/tests/gd2/CMakeLists.txt
47 diff --git a/tests/gd2/Makemodule.am b/tests/gd2/Makemodule.am
48 index 754a284..b8ee946 100644
49 --- a/tests/gd2/Makemodule.am
50 +++ b/tests/gd2/Makemodule.am
52 libgd_test_programs += \
57 diff --git a/tests/gd2/bug_289.c b/tests/gd2/bug_289.c
59 index 0000000..ad311e9
61 +++ b/tests/gd2/bug_289.c
64 + * Passing an unrecognized format to gdImageGd2() should result in
65 + * GD2_FMT_TRUECOLOR_COMPRESSED for truecolor images.
67 + * See <https://github.com/libgd/libgd/issues/289>.
74 +#define GD2_FMT_UNRECOGNIZED 0
75 +#define GD2_FMT_TRUECOLOR_COMPRESSED 4
77 +#define MSG "expected %s byte to be %d, but got %d\n"
86 + im = gdImageCreateTrueColor(10, 10);
87 + gdTestAssert(im != NULL);
88 + buffer = (char *) gdImageGd2Ptr(im, 128, GD2_FMT_UNRECOGNIZED, &size);
89 + gdTestAssert(buffer != NULL);
91 + gdTestAssertMsg(buffer[12] == 0, MSG, "1st", 0, buffer[12]);
92 + gdTestAssertMsg(buffer[13] == GD2_FMT_TRUECOLOR_COMPRESSED, MSG, "2nd", GD2_FMT_TRUECOLOR_COMPRESSED, buffer[13]);
94 + return gdNumFailures();