summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-01-04 16:18:42 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-01-04 19:06:51 +0100
commit7a06c1669c563917bc48c464521e3de962ddb4e8 (patch)
tree12e5c5cc5760f834022341a55a438946b9fa9b1f /tests
parentc8438b3b729fe3f98439eba538bf6c681afb65ba (diff)
downloadlibgd-7a06c1669c563917bc48c464521e3de962ddb4e8.tar.gz
Fix #583: gdTransformAffineCopy() may use unitialized values
We have to check the return value of `gdAffineInvert()`, and on failure let `gdTransformAffineCopy()` fail as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/gdtransformaffinecopy/.gitignore1
-rw-r--r--tests/gdtransformaffinecopy/CMakeLists.txt5
-rw-r--r--tests/gdtransformaffinecopy/Makemodule.am5
-rw-r--r--tests/gdtransformaffinecopy/github_bug_00583.c30
6 files changed, 43 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 05904cd..8a39995 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -75,6 +75,7 @@ if (BUILD_TEST)
gdtest
gdtiled
gdtransformaffineboundingbox
+ gdtransformaffinecopy
gif
jpeg
png
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f672032..9c98a3c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -71,6 +71,7 @@ include gdnewfilectx/Makemodule.am
include gdtest/Makemodule.am
include gdtiled/Makemodule.am
include gdtransformaffineboundingbox/Makemodule.am
+include gdtransformaffinecopy/Makemodule.am
include gif/Makemodule.am
include jpeg/Makemodule.am
include png/Makemodule.am
diff --git a/tests/gdtransformaffinecopy/.gitignore b/tests/gdtransformaffinecopy/.gitignore
new file mode 100644
index 0000000..a6b56ec
--- /dev/null
+++ b/tests/gdtransformaffinecopy/.gitignore
@@ -0,0 +1 @@
+/github_bug_00583
diff --git a/tests/gdtransformaffinecopy/CMakeLists.txt b/tests/gdtransformaffinecopy/CMakeLists.txt
new file mode 100644
index 0000000..69472fb
--- /dev/null
+++ b/tests/gdtransformaffinecopy/CMakeLists.txt
@@ -0,0 +1,5 @@
+LIST(APPEND TESTS_FILES
+ github_bug_00583
+)
+
+ADD_GD_TESTS()
diff --git a/tests/gdtransformaffinecopy/Makemodule.am b/tests/gdtransformaffinecopy/Makemodule.am
new file mode 100644
index 0000000..f86b3c9
--- /dev/null
+++ b/tests/gdtransformaffinecopy/Makemodule.am
@@ -0,0 +1,5 @@
+libgd_test_programs += \
+ gdtransformaffinecopy/github_bug_00583
+
+EXTRA_DIST += \
+ gdtransformaffinecopy/CMakeLists.txt
diff --git a/tests/gdtransformaffinecopy/github_bug_00583.c b/tests/gdtransformaffinecopy/github_bug_00583.c
new file mode 100644
index 0000000..4bdee0a
--- /dev/null
+++ b/tests/gdtransformaffinecopy/github_bug_00583.c
@@ -0,0 +1,30 @@
+/**
+ * Test that a zero determinant matrix causes gdTransformAffineCopy() to fail
+ *
+ * See <https://github.com/libgd/libgd/issues/583>
+ */
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+int main()
+{
+ gdImagePtr src, dst;
+ gdRect rect = {0, 0, 8, 8};
+ double matrix[] = {1, 1, 1, 1, 1, 1};
+ int white;
+ int res;
+
+ src = gdImageCreateTrueColor(8, 8);
+ gdTestAssert(src != NULL);
+ dst = gdImageCreateTrueColor(8, 8);
+ gdTestAssert(dst != NULL);
+ white = gdImageColorAllocate(src, 255, 255, 255);
+ gdImageFilledRectangle(src, 0, 0, 7, 7, white);
+ res = gdTransformAffineCopy(dst, 0, 0, src, &rect, matrix);
+ gdTestAssert(res == GD_FALSE);
+ gdImageDestroy(dst);
+ gdImageDestroy(src);
+ return gdNumFailures();
+}