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
parent
5ebbd50cff
commit
fea55903ee
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/bug00338
|
||||
/bug_github_18
|
||||
/jpeg_empty_file
|
||||
/jpeg_im2im
|
||||
|
|
|
@ -5,6 +5,7 @@ LIST(APPEND TESTS_FILES
|
|||
jpeg_read
|
||||
jpeg_empty_file
|
||||
jpeg_resolution
|
||||
bug00338
|
||||
bug_github_18
|
||||
)
|
||||
ENDIF(JPEG_FOUND)
|
||||
|
|
|
@ -7,6 +7,7 @@ libgd_test_programs += \
|
|||
|
||||
if HAVE_LIBPNG
|
||||
libgd_test_programs += \
|
||||
jpeg/bug00338 \
|
||||
jpeg/jpeg_read \
|
||||
jpeg/jpeg_resolution
|
||||
endif
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
/bug00086
|
||||
/bug00088
|
||||
/bug00193
|
||||
/bug00338
|
||||
/png_im2im
|
||||
/png_null
|
||||
/png_resolution
|
||||
|
|
|
@ -8,6 +8,7 @@ LIST(APPEND TESTS_FILES
|
|||
bug00086
|
||||
bug00088
|
||||
bug00193
|
||||
bug00338
|
||||
)
|
||||
ENDIF(PNG_FOUND)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ libgd_test_programs += \
|
|||
png/bug00086 \
|
||||
png/bug00088 \
|
||||
png/bug00193 \
|
||||
png/bug00338 \
|
||||
png/png_im2im \
|
||||
png/png_null \
|
||||
png/png_resolution
|
||||
|
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue