From 79f95bf162e79a70587fdad761c9e8d1e5ed592a Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Tue, 9 Jul 2013 23:30:48 +1000 Subject: [PATCH] [rt #86659] PNG benign error support is more complex than a version check --- PNG/PNG.xs | 14 ++++++++++++++ PNG/impng.c | 37 ++++++++++++++++++++++++++++++++++++- PNG/impng.h | 3 +++ PNG/t/10png.t | 6 ++++-- lib/Imager/Files.pod | 3 ++- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/PNG/PNG.xs b/PNG/PNG.xs index 1048b448..242c77db 100644 --- a/PNG/PNG.xs +++ b/PNG/PNG.xs @@ -26,6 +26,20 @@ i_writepng_wiol(im, ig) unsigned i_png_lib_version() +MODULE = Imager::File::PNG PACKAGE = Imager::File::PNG PREFIX=i_png_ + +void +i_png_features(...) + PREINIT: + const char * const *p; + PPCODE: + p = i_png_features(); + while (*p) { + EXTEND(SP, 1); + PUSHs(sv_2mortal(newSVpv(*p, 0))); + ++p; + } + int IMPNG_READ_IGNORE_BENIGN_ERRORS() CODE: diff --git a/PNG/impng.c b/PNG/impng.c index dcc85242..ac3f9fe1 100644 --- a/PNG/impng.c +++ b/PNG/impng.c @@ -48,6 +48,35 @@ i_png_lib_version(void) { return png_access_version_number(); } +static char const * const +features[] = + { +#ifdef PNG_BENIGN_ERRORS_SUPPORTED + "benign-errors", +#endif +#ifdef PNG_READ_SUPPORTED + "read", +#endif +#ifdef PNG_WRITE_SUPPORTED + "write", +#endif +#ifdef PNG_MNG_FEATURES_SUPPORTED + "mng-features", +#endif +#ifdef PNG_CHECK_cHRM_SUPPORTED + "check-cHRM", +#endif +#ifdef PNG_SET_USER_LIMITS_SUPPORTED + "user-limits", +#endif + NULL + }; + +const char * const * +i_png_features(void) { + return features; +} + static void wiol_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { io_glue *ig = png_get_io_ptr(png_ptr); @@ -295,8 +324,14 @@ i_readpng_wiol(io_glue *ig, int flags) { } png_set_read_fn(png_ptr, (png_voidp) (ig), wiol_read_data); -#if PNG_LIBPNG_VER >= 10400 +#if defined(PNG_BENIGN_ERRORS_SUPPORTED) png_set_benign_errors(png_ptr, (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) ? 1 : 0); +#elif PNG_LIBPNG_VER >= 10400 + if (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) { + i_push_error(0, "libpng not configured to ignore benign errors"); + png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); + return NULL; + } #else if (flags & IMPNG_READ_IGNORE_BENIGN_ERRORS) { i_push_error(0, "libpng too old to ignore benign errors"); diff --git a/PNG/impng.h b/PNG/impng.h index af8225a2..f27a825d 100644 --- a/PNG/impng.h +++ b/PNG/impng.h @@ -10,4 +10,7 @@ i_img *i_readpng_wiol(io_glue *ig, int flags); undef_int i_writepng_wiol(i_img *im, io_glue *ig); unsigned i_png_lib_version(void); +extern const char * const * +i_png_features(void); + #endif diff --git a/PNG/t/10png.t b/PNG/t/10png.t index 4cabe536..bc109d72 100644 --- a/PNG/t/10png.t +++ b/PNG/t/10png.t @@ -17,6 +17,8 @@ ok($Imager::formats{"png"}, "must have png format"); diag("Library version " . Imager::File::PNG::i_png_lib_version()); +my %png_feat = map { $_ => 1 } Imager::File::PNG->features; + my $green = i_color_new(0, 255, 0, 255); my $blue = i_color_new(0, 0, 255, 255); my $red = i_color_new(255, 0, 0, 255); @@ -180,8 +182,8 @@ EOS SKIP: { # ignoring "benign" errors - Imager::File::PNG::i_png_lib_version() > 10400 - or skip "Cannot skip benign errors in libpng this old", 1; + $png_feat{"benign-errors"} + or skip "libpng not configured for benign error support", 1; my $im = Imager->new; ok($im->read(file => "testimg/badcrc.png", type => "png", png_ignore_benign_errors => 1), diff --git a/lib/Imager/Files.pod b/lib/Imager/Files.pod index 88f5dc68..a00a0d51 100644 --- a/lib/Imager/Files.pod +++ b/lib/Imager/Files.pod @@ -1476,7 +1476,8 @@ C - set from the C when reading an image file. =for stopwords CRC -XIf you're using F 1.4 or later, you +XIf you're using F 1.6 or later, or +an earlier release configured with C, you can choose to ignore file format errors the authors of F consider I, this includes at least CRC errors and palette index overflows. Do this by supplying a true value for the -- 2.39.5