From cc380975602715ea760606ca57bea2de51678647 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 26 Apr 2017 10:25:52 +0100 Subject: [PATCH] better handling of truncated PNG files improve fail support, and bail out sooner see https://github.com/jcupitt/libvips/issues/646 --- ChangeLog | 1 + libvips/foreign/vipspng.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae223c70..b099728a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 23/4/17 started 8.5.5 - doc polishing +- more improvements for tuncated PNG files, thanks juyunsang 23/4/17 started 8.5.4 - don't depend on image width when setting n_lines, thanks kleisauke diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index df3716bc..df076ff3 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -63,6 +63,8 @@ * - use dbuf for buffer output * 30/3/17 * - better behaviour for truncated png files, thanks Yury + * 26/4/17 + * - better @fail handling with truncated PNGs */ /* @@ -127,8 +129,8 @@ user_error_function( png_structp png_ptr, png_const_charp error_msg ) /* This function must not return or the default error handler will be * invoked. - longjmp( png_jmpbuf( png_ptr ), -1 ); */ + longjmp( png_jmpbuf( png_ptr ), -1 ); } static void @@ -409,7 +411,7 @@ png2vips_header( Read *read, VipsImage *out ) void *profile_copy; #ifdef DEBUG - printf( "png2vips_header: attaching %zd bytes of ICC profile\n", + printf( "png2vips_header: attaching %d bytes of ICC profile\n", proflen ); printf( "png2vips_header: name = \"%s\"\n", name ); #endif /*DEBUG*/ @@ -538,6 +540,11 @@ png2vips_generate( VipsRegion *or, printf( "png2vips_generate: thread %p\n", g_thread_self() ); #endif /*DEBUG*/ + + /* ... except if fail is on, in which case we bail out. + */ + if( read->fail ) + return( -1 ); } read->y_pos += 1;