diff --git a/src/gd_jpeg.c b/src/gd_jpeg.c index 744f229..271ef46 100644 --- a/src/gd_jpeg.c +++ b/src/gd_jpeg.c @@ -108,7 +108,7 @@ static void fatal_jpeg_error(j_common_ptr cinfo) char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, buffer); - gd_error_ex(GD_ERROR, "gd-jpeg: JPEG library reports unrecoverable error: %s", buffer); + gd_error_ex(GD_WARNING, "gd-jpeg: JPEG library reports unrecoverable error: %s", buffer); jmpbufw = (jmpbuf_wrapper *)cinfo->client_data; jpeg_destroy(cinfo); diff --git a/src/gd_png.c b/src/gd_png.c index db8de72..9dca659 100644 --- a/src/gd_png.c +++ b/src/gd_png.c @@ -68,7 +68,7 @@ gdPngErrorHandler (png_structp png_ptr, png_const_charp msg) * regardless of whether _BSD_SOURCE or anything else has (or has not) * been defined. */ - gd_error_ex(GD_ERROR, "gd-png: fatal libpng error: %s\n", msg); + gd_error_ex(GD_WARNING, "gd-png: fatal libpng error: %s\n", msg); jmpbuf_ptr = png_get_error_ptr (png_ptr); if (jmpbuf_ptr == NULL) { /* we are completely hosed now */ 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 + * + * 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 +#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(); +} diff --git a/tests/png/.gitignore b/tests/png/.gitignore index 28eb412..97972c1 100644 --- a/tests/png/.gitignore +++ b/tests/png/.gitignore @@ -3,6 +3,7 @@ /bug00086 /bug00088 /bug00193 +/bug00338 /png_im2im /png_null /png_resolution diff --git a/tests/png/CMakeLists.txt b/tests/png/CMakeLists.txt index 228474e..a577a67 100644 --- a/tests/png/CMakeLists.txt +++ b/tests/png/CMakeLists.txt @@ -8,6 +8,7 @@ LIST(APPEND TESTS_FILES bug00086 bug00088 bug00193 + bug00338 ) ENDIF(PNG_FOUND) diff --git a/tests/png/Makemodule.am b/tests/png/Makemodule.am index 01c4803..7e73dd6 100644 --- a/tests/png/Makemodule.am +++ b/tests/png/Makemodule.am @@ -5,6 +5,7 @@ libgd_test_programs += \ png/bug00086 \ png/bug00088 \ png/bug00193 \ + png/bug00338 \ png/png_im2im \ png/png_null \ png/png_resolution diff --git a/tests/png/bug00338.c b/tests/png/bug00338.c new file mode 100644 index 0000000..af16df1 --- /dev/null +++ b/tests/png/bug00338.c @@ -0,0 +1,48 @@ +/** + * Regression test for + * + * We're testing that writing a PNG image with an unsupported quality + * raises a GD_WARNING for the fatal libpng error, but not a GD_ERROR. + * We also make sure, that the fatal libpng error is actually reported. + * + * See also ../jpeg/bug00338.c + */ + + +#include +#include "gd.h" +#include "gd_errors.h" +#include "gdtest.h" + + +#define MSG "gd-png: fatal libpng error: %s\n" + + +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(); + gdImagePngEx(im, fp, 100); + gdImageDestroy(im); + + gdTestAssert(error_handler_called); + + return gdNumFailures(); +}