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.
master
Christoph M. Becker 2016-11-16 18:10:29 +01:00
parent 5ebbd50cff
commit fea55903ee
10 changed files with 107 additions and 2 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -1,3 +1,4 @@
/bug00338
/bug_github_18
/jpeg_empty_file
/jpeg_im2im

View File

@ -5,6 +5,7 @@ LIST(APPEND TESTS_FILES
jpeg_read
jpeg_empty_file
jpeg_resolution
bug00338
bug_github_18
)
ENDIF(JPEG_FOUND)

View File

@ -7,6 +7,7 @@ libgd_test_programs += \
if HAVE_LIBPNG
libgd_test_programs += \
jpeg/bug00338 \
jpeg/jpeg_read \
jpeg/jpeg_resolution
endif

51
tests/jpeg/bug00338.c Normal file
View File

@ -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();
}

View File

@ -3,6 +3,7 @@
/bug00086
/bug00088
/bug00193
/bug00338
/png_im2im
/png_null
/png_resolution

View File

@ -8,6 +8,7 @@ LIST(APPEND TESTS_FILES
bug00086
bug00088
bug00193
bug00338
)
ENDIF(PNG_FOUND)

View File

@ -5,6 +5,7 @@ libgd_test_programs += \
png/bug00086 \
png/bug00088 \
png/bug00193 \
png/bug00338 \
png/png_im2im \
png/png_null \
png/png_resolution

48
tests/png/bug00338.c Normal file
View File

@ -0,0 +1,48 @@
/**
* Regression test for <https://github.com/libgd/libgd/issues/338>
*
* 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 <string.h>
#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();
}