unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob ce69a735007e46cf14d8df8346566aebae22b8ab 3197 bytes (raw)
name: gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch 	 # note: path name is non-authoritative(*)

  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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
 
From 082c5444838ea0d84f9fb6441aefdb44d78d9bba Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmbecker69@gmx.de>
Date: Fri, 20 Jan 2017 22:48:20 +0100
Subject: [PATCH] Fix #109: XBM reading fails with printed error

When calculating the number of required bytes of an XBM image, we have
to take the line padding into account.
---
 src/gd_xbm.c                     |   2 +-
 tests/xbm/CMakeLists.txt         |   1 +
 tests/xbm/Makemodule.am          |   5 ++++-
 tests/xbm/github_bug_109.c       |  35 +++++++++++++++++++++++++++++++++++
 tests/xbm/github_bug_109.xbm     |   5 +++++
 5 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 tests/xbm/github_bug_109.c
 create mode 100644 tests/xbm/github_bug_109.xbm
 create mode 100644 tests/xbm/github_bug_109_exp.png

diff --git a/src/gd_xbm.c b/src/gd_xbm.c
index 5f09b56..c2ba2ad 100644
--- a/src/gd_xbm.c
+++ b/src/gd_xbm.c
@@ -108,7 +108,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm(FILE * fd)
 				max_bit = 32768;
 			}
 			if (max_bit) {
-				bytes = (width * height / 8) + 1;
+                bytes = (width + 7) / 8 * height;
 				if (!bytes) {
 					return 0;
 				}
diff --git a/tests/xbm/CMakeLists.txt b/tests/xbm/CMakeLists.txt
index 183cf5e..08576e0 100644
--- a/tests/xbm/CMakeLists.txt
+++ b/tests/xbm/CMakeLists.txt
@@ -1,4 +1,5 @@
 LIST(APPEND TESTS_FILES
+	github_bug_109
 	github_bug_170
 )
 
diff --git a/tests/xbm/Makemodule.am b/tests/xbm/Makemodule.am
index ba1eabd..0f5beb6 100644
--- a/tests/xbm/Makemodule.am
+++ b/tests/xbm/Makemodule.am
@@ -1,5 +1,8 @@
 libgd_test_programs += \
+	xbm/github_bug_109 \
 	xbm/github_bug_170
 
 EXTRA_DIST += \
-	xbm/CMakeLists.txt
+	xbm/CMakeLists.txt \
+	xbm/github_bug_109.xbm \
+	xbm/github_bug_109_exp.png
diff --git a/tests/xbm/github_bug_109.c b/tests/xbm/github_bug_109.c
new file mode 100644
index 0000000..1a020c6
--- /dev/null
+++ b/tests/xbm/github_bug_109.c
@@ -0,0 +1,35 @@
+/**
+ * Test reading of XBM images with a width that is not a multiple of 8
+ *
+ * We're reading such an XBM image, and check that we got what we've expected,
+ * instead of an error message.
+ *
+ * See also <https://github.com/libgd/libgd/issues/109>.
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+int main()
+{
+    gdImagePtr im;
+    FILE *fp;
+    char *path;
+
+    fp = gdTestFileOpen2("xbm", "github_bug_109.xbm");
+    im = gdImageCreateFromXbm(fp);
+    fclose(fp);
+    gdTestAssert(im != NULL);
+    gdTestAssert(gdImageGetTrueColorPixel(im, 0, 0) == 0);
+    gdTestAssert(gdImageGetTrueColorPixel(im, 0, 1) == 0xffffff);
+
+    path = gdTestFilePath2("xbm", "github_bug_109_exp.png");
+    gdAssertImageEqualsToFile(path, im);
+    gdFree(path);
+
+    gdImageDestroy(im);
+
+    return gdNumFailures();
+}
diff --git a/tests/xbm/github_bug_109.xbm b/tests/xbm/github_bug_109.xbm
new file mode 100644
index 0000000..f427d86
--- /dev/null
+++ b/tests/xbm/github_bug_109.xbm
@@ -0,0 +1,5 @@
+#define test_width 10
+#define test_height 10
+static unsigned char test_bits[] = {
+  0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 
+  0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00};

-- 
2.7.4


debug log:

solving ce69a73 ...
found ce69a73 in https://yhetil.org/guix-devel/8f6832f9733657f49554484ee4724000@lepiller.eu/

applying [1/1] https://yhetil.org/guix-devel/8f6832f9733657f49554484ee4724000@lepiller.eu/
diff --git a/gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch b/gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch
new file mode 100644
index 0000000..ce69a73

1:30: space before tab in indent.
 				max_bit = 32768;
1:31: space before tab in indent.
 			}
1:32: space before tab in indent.
 			if (max_bit) {
1:35: space before tab in indent.
 				if (!bytes) {
1:36: space before tab in indent.
 					return 0;
Checking patch gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch...
Applied patch gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch cleanly.
warning: squelched 43 whitespace errors
warning: 48 lines add whitespace errors.

index at:
100644 ce69a735007e46cf14d8df8346566aebae22b8ab	gnu/packages/patches/gd-php-73968-Fix-109-XBM-reading.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).