summaryrefslogtreecommitdiff
path: root/tests/jpeg
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2016-11-16 18:10:29 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2016-11-16 18:10:29 +0100
commitfea55903eeeb89d4a0117519f8c1d039adc95da5 (patch)
tree23fece8c3691331b5b6f1918b718319970e5ebcf /tests/jpeg
parent5ebbd50cffc013a7dd0f3b1eaaa83d199e8e47fd (diff)
downloadlibgd-fea55903eeeb89d4a0117519f8c1d039adc95da5.tar.gz
Fix #338: Fatal and normal libjpeg/ibpng errors not distinguishable
libgd clients need to be able to distinguish between fatal and "extremely fatal" libjpeg and libpng errors, because in the former case execution can proceed, but in the latter case libgd calls exit(). Therefore we report fatal errors as GD_WARNING.
Diffstat (limited to 'tests/jpeg')
-rw-r--r--tests/jpeg/.gitignore1
-rw-r--r--tests/jpeg/CMakeLists.txt1
-rw-r--r--tests/jpeg/Makemodule.am1
-rw-r--r--tests/jpeg/bug00338.c51
4 files changed, 54 insertions, 0 deletions
diff --git a/tests/jpeg/.gitignore b/tests/jpeg/.gitignore
index 06cc9b2..c28aa87 100644
--- a/tests/jpeg/.gitignore
+++ b/tests/jpeg/.gitignore
@@ -1,3 +1,4 @@
+/bug00338
/bug_github_18
/jpeg_empty_file
/jpeg_im2im
diff --git a/tests/jpeg/CMakeLists.txt b/tests/jpeg/CMakeLists.txt
index e8ecf63..04d6483 100644
--- a/tests/jpeg/CMakeLists.txt
+++ b/tests/jpeg/CMakeLists.txt
@@ -5,6 +5,7 @@ LIST(APPEND TESTS_FILES
jpeg_read
jpeg_empty_file
jpeg_resolution
+ bug00338
bug_github_18
)
ENDIF(JPEG_FOUND)
diff --git a/tests/jpeg/Makemodule.am b/tests/jpeg/Makemodule.am
index bc196b1..d09f9c5 100644
--- a/tests/jpeg/Makemodule.am
+++ b/tests/jpeg/Makemodule.am
@@ -7,6 +7,7 @@ libgd_test_programs += \
if HAVE_LIBPNG
libgd_test_programs += \
+ jpeg/bug00338 \
jpeg/jpeg_read \
jpeg/jpeg_resolution
endif
diff --git a/tests/jpeg/bug00338.c b/tests/jpeg/bug00338.c
new file mode 100644
index 0000000..92c55a9
--- /dev/null
+++ b/tests/jpeg/bug00338.c
@@ -0,0 +1,51 @@
+/**
+ * Regression test for <https://github.com/libgd/libgd/issues/338>
+ *
+ * We're testing that reading a PNG image with gdImageCreateFromJpeg()
+ * raises a GD_WARNING for the fatal libjpeg error, but not a GD_ERROR.
+ * We also make sure, that the fatal libjpeg error is actually reported.
+ *
+ * See also ../png/bug00338.c
+ */
+
+
+#include <string.h>
+#include "gd.h"
+#include "gd_errors.h"
+#include "gdtest.h"
+
+
+#define MSG "gd-jpeg: JPEG library reports unrecoverable error: %s"
+
+
+static int error_handler_called = 0;
+
+
+static void error_handler(int priority, const char *format, va_list args)
+{
+ if (!strcmp(format, MSG)) {
+ gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority);
+ error_handler_called = 1;
+ }
+}
+
+
+int main()
+{
+ gdImagePtr im;
+ FILE *fp;
+
+ gdSetErrorMethod(error_handler);
+
+ im = gdImageCreateTrueColor(10, 10);
+ fp = gdTestTempFp();
+ gdImagePng(im, fp);
+ gdImageDestroy(im);
+
+ im = gdImageCreateFromJpeg(fp);
+ gdTestAssert(im == NULL);
+
+ gdTestAssert(error_handler_called);
+
+ return gdNumFailures();
+}