From 2b75a372d12b0a2c331b8faa4c84cbe314cb8fd4 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 3 May 2017 10:32:24 +0100 Subject: [PATCH] more truncated png improvements --- ChangeLog | 2 +- libvips/foreign/vipspng.c | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b099728a..2ba61bec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 23/4/17 started 8.5.5 - doc polishing -- more improvements for tuncated PNG files, thanks juyunsang +- more improvements for truncated 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 df076ff3..7c5b0809 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -125,7 +125,11 @@ static void user_error_function( png_structp png_ptr, png_const_charp error_msg ) { - vips_error( "vipspng", "%s", error_msg ); +#ifdef DEBUG + printf( "user_error_function: %s\n", error_msg ); +#endif /*DEBUG*/ + + g_warning( "%s", error_msg ); /* This function must not return or the default error handler will be * invoked. @@ -136,7 +140,11 @@ user_error_function( png_structp png_ptr, png_const_charp error_msg ) static void user_warning_function( png_structp png_ptr, png_const_charp warning_msg ) { - vips_error( "vipspng", "%s", warning_msg ); +#ifdef DEBUG + printf( "user_warning_function: %s\n", warning_msg ); +#endif /*DEBUG*/ + + g_warning( "%s", warning_msg ); } /* What we track during a PNG read. @@ -523,7 +531,7 @@ png2vips_generate( VipsRegion *or, for( y = 0; y < r->height; y++ ) { png_bytep q = (png_bytep) VIPS_REGION_ADDR( or, 0, r->top + y ); - /* We need to catch and ignore errors from read_row(). + /* We need to catch errors from read_row(). */ if( !setjmp( png_jmpbuf( read->pPng ) ) ) png_read_row( read->pPng, q, NULL ); @@ -541,21 +549,28 @@ png2vips_generate( VipsRegion *or, g_thread_self() ); #endif /*DEBUG*/ - /* ... except if fail is on, in which case we bail out. + /* And bail if fail is on. We have to add an error + * message, since the handler we install just does + * g_warning(). */ - if( read->fail ) + if( read->fail ) { + vips_error( "vipspng", + "%s", _( "libpng read error" ) ); return( -1 ); + } } read->y_pos += 1; } - /* Turn errors back on. png_read_end() can trigger them too, for - * example for a truncated file. + /* Catch errors from png_read_end(). This can fail on a truncated + * file. */ if( setjmp( png_jmpbuf( read->pPng ) ) ) { - if( read->fail ) + if( read->fail ) { + vips_error( "vipspng", "%s", _( "libpng read error" ) ); return( -1 ); + } return( 0 ); }