unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob be3eff9327a5613f97ee59959bfa56fd9eee4479 2860 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
This fixes PHP bug #73159: https://bugs.php.net/bug.php?id=73159

Patch lifted from upstream source repository:

https://github.com/libgd/libgd/commit/e1f61a4141d2e0937a13b8bfb1992b9f29eb05f5

From e1f61a4141d2e0937a13b8bfb1992b9f29eb05f5 Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmbecker69@gmx.de>
Date: Mon, 15 Aug 2016 17:49:40 +0200
Subject: [PATCH] Fix #289: Passing unrecognized formats to gdImageGd2 results
 in corrupted files

We must not apply the format correction twice for truecolor images.

(cherry picked from commit 09090c125658e23a4ae2a2e002646bb7278bd89e)
---
 src/gd_gd2.c             |  2 +-
 tests/gd2/CMakeLists.txt |  1 +
 tests/gd2/Makemodule.am  |  1 +
 tests/gd2/bug_289.c      | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 tests/gd2/bug_289.c

diff --git a/src/gd_gd2.c b/src/gd_gd2.c
index 86c881e..75e5e1f 100644
--- a/src/gd_gd2.c
+++ b/src/gd_gd2.c
@@ -918,7 +918,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
 	/* Force fmt to a valid value since we don't return anything. */
 	/* */
 	if ((fmt != GD2_FMT_RAW) && (fmt != GD2_FMT_COMPRESSED)) {
-		fmt = im->trueColor ? GD2_FMT_TRUECOLOR_COMPRESSED : GD2_FMT_COMPRESSED;
+		fmt = GD2_FMT_COMPRESSED;
 	};
 	if (im->trueColor) {
 		fmt += 2;
diff --git a/tests/gd2/CMakeLists.txt b/tests/gd2/CMakeLists.txt
index 8aecacc..3b650ad 100644
--- a/tests/gd2/CMakeLists.txt
+++ b/tests/gd2/CMakeLists.txt
@@ -1,4 +1,5 @@
 SET(TESTS_FILES
+	bug_289
 	gd2_empty_file
 	gd2_im2im
 	gd2_null
diff --git a/tests/gd2/Makemodule.am b/tests/gd2/Makemodule.am
index 754a284..b8ee946 100644
--- a/tests/gd2/Makemodule.am
+++ b/tests/gd2/Makemodule.am
@@ -1,4 +1,5 @@
 libgd_test_programs += \
+	gd2/bug_289 \
 	gd2/gd2_empty_file \
 	gd2/php_bug_72339 \
 	gd2/gd2_read_corrupt
diff --git a/tests/gd2/bug_289.c b/tests/gd2/bug_289.c
new file mode 100644
index 0000000..ad311e9
--- /dev/null
+++ b/tests/gd2/bug_289.c
@@ -0,0 +1,33 @@
+/**
+ * Passing an unrecognized format to gdImageGd2() should result in
+ * GD2_FMT_TRUECOLOR_COMPRESSED for truecolor images.
+ *
+ * See <https://github.com/libgd/libgd/issues/289>.
+ */
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+#define GD2_FMT_UNRECOGNIZED 0
+#define GD2_FMT_TRUECOLOR_COMPRESSED 4
+
+#define MSG "expected %s byte to be %d, but got %d\n"
+
+
+int main()
+{
+    gdImagePtr im;
+    char *buffer;
+    int size;
+
+    im = gdImageCreateTrueColor(10, 10);
+    gdTestAssert(im != NULL);
+    buffer = (char *) gdImageGd2Ptr(im, 128, GD2_FMT_UNRECOGNIZED, &size);
+    gdTestAssert(buffer != NULL);
+    gdImageDestroy(im);
+    gdTestAssertMsg(buffer[12] == 0, MSG, "1st", 0, buffer[12]);
+    gdTestAssertMsg(buffer[13] == GD2_FMT_TRUECOLOR_COMPRESSED, MSG, "2nd", GD2_FMT_TRUECOLOR_COMPRESSED, buffer[13]);
+
+    return gdNumFailures();
+}

debug log:

solving be3eff9 ...
found be3eff9 in https://git.savannah.gnu.org/cgit/guix.git

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).