gnu: Add php.
[jackhill/guix/guix.git] / gnu / packages / patches / gd-fix-truecolor-format-correction.patch
1 This fixes PHP bug #73159: https://bugs.php.net/bug.php?id=73159
2
3 Patch lifted from upstream source repository:
4
5 https://github.com/libgd/libgd/commit/e1f61a4141d2e0937a13b8bfb1992b9f29eb05f5
6
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
11 in corrupted files
12
13 We must not apply the format correction twice for truecolor images.
14
15 (cherry picked from commit 09090c125658e23a4ae2a2e002646bb7278bd89e)
16 ---
17 src/gd_gd2.c | 2 +-
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
23
24 diff --git a/src/gd_gd2.c b/src/gd_gd2.c
25 index 86c881e..75e5e1f 100644
26 --- a/src/gd_gd2.c
27 +++ b/src/gd_gd2.c
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. */
30 /* */
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;
34 };
35 if (im->trueColor) {
36 fmt += 2;
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
41 @@ -1,4 +1,5 @@
42 SET(TESTS_FILES
43 + bug_289
44 gd2_empty_file
45 gd2_im2im
46 gd2_null
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
51 @@ -1,4 +1,5 @@
52 libgd_test_programs += \
53 + gd2/bug_289 \
54 gd2/gd2_empty_file \
55 gd2/php_bug_72339 \
56 gd2/gd2_read_corrupt
57 diff --git a/tests/gd2/bug_289.c b/tests/gd2/bug_289.c
58 new file mode 100644
59 index 0000000..ad311e9
60 --- /dev/null
61 +++ b/tests/gd2/bug_289.c
62 @@ -0,0 +1,33 @@
63 +/**
64 + * Passing an unrecognized format to gdImageGd2() should result in
65 + * GD2_FMT_TRUECOLOR_COMPRESSED for truecolor images.
66 + *
67 + * See <https://github.com/libgd/libgd/issues/289>.
68 + */
69 +
70 +#include "gd.h"
71 +#include "gdtest.h"
72 +
73 +
74 +#define GD2_FMT_UNRECOGNIZED 0
75 +#define GD2_FMT_TRUECOLOR_COMPRESSED 4
76 +
77 +#define MSG "expected %s byte to be %d, but got %d\n"
78 +
79 +
80 +int main()
81 +{
82 + gdImagePtr im;
83 + char *buffer;
84 + int size;
85 +
86 + im = gdImageCreateTrueColor(10, 10);
87 + gdTestAssert(im != NULL);
88 + buffer = (char *) gdImageGd2Ptr(im, 128, GD2_FMT_UNRECOGNIZED, &size);
89 + gdTestAssert(buffer != NULL);
90 + gdImageDestroy(im);
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]);
93 +
94 + return gdNumFailures();
95 +}