From 4285118880f5a563d598eb04bd72de0bec4b9913 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 17 May 2016 19:43:47 +0100 Subject: [PATCH 1/2] more robust vips file read --- libvips/iofuncs/buffer.c | 2 +- libvips/iofuncs/sinkdisc.c | 3 ++- libvips/iofuncs/vips.c | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libvips/iofuncs/buffer.c b/libvips/iofuncs/buffer.c index e5f4cdd8..bb7f7ec7 100644 --- a/libvips/iofuncs/buffer.c +++ b/libvips/iofuncs/buffer.c @@ -156,7 +156,7 @@ vips_buffer_dump_all( void ) static void vips_buffer_free( VipsBuffer *buffer ) { - vips_tracked_free( buffer->buf ); + VIPS_FREEF( vips_tracked_free, buffer->buf ); buffer->bsize = 0; g_free( buffer ); diff --git a/libvips/iofuncs/sinkdisc.c b/libvips/iofuncs/sinkdisc.c index 8c1fd067..f686d6fc 100644 --- a/libvips/iofuncs/sinkdisc.c +++ b/libvips/iofuncs/sinkdisc.c @@ -300,7 +300,8 @@ wbuffer_position( WriteBuffer *wbuffer, int top, int height ) /* This should be an exclusive buffer, hopefully. */ - g_assert( !wbuffer->region->buffer->done ); + if( !result ) + g_assert( !wbuffer->region->buffer->done ); return( result ); } diff --git a/libvips/iofuncs/vips.c b/libvips/iofuncs/vips.c index 6502f0d6..9ed6b814 100644 --- a/libvips/iofuncs/vips.c +++ b/libvips/iofuncs/vips.c @@ -792,7 +792,7 @@ vips__write_extension_block( VipsImage *im, void *buf, int size ) psize = image_pixel_length( im ); if( (length = vips_file_length( im->fd )) == -1 ) return( -1 ); - if( length - psize < 0 ) { + if( length < psize ) { vips_error( "VipsImage", "%s", _( "file has been truncated" ) ); return( -1 ); } @@ -894,13 +894,15 @@ vips_image_open_input( VipsImage *image ) return( -1 ); } - /* Predict and check the file size. + /* Predict and check the file size. Only issue a warning, we want to be + * able to read all the header fields we can, even if the actual data + * isn't there. */ psize = image_pixel_length( image ); if( (rsize = vips_file_length( image->fd )) == -1 ) return( -1 ); image->file_length = rsize; - if( psize > rsize ) + if( psize > rsize ) vips_warn( "VipsImage", _( "unable to read data for \"%s\", %s" ), image->filename, _( "file has been truncated" ) ); From 7ec63c4451498eb8ce7ec0d3dd54b704f15a567e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 17 May 2016 21:58:52 +0100 Subject: [PATCH 2/2] more vips image read fixing thanks AFL! --- ChangeLog | 3 +++ configure.ac | 6 +++--- libvips/iofuncs/header.c | 3 +-- libvips/iofuncs/image.c | 11 +++++++---- libvips/iofuncs/threadpool.c | 6 ++++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b926428..600f20f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +18/5/16 started 8.3.2 +- more robust vips image reading + 15/4/16 started 8.3.1 - rename vips wrapper script, it was still vips-8.2, thanks Benjamin - export C++ operator overloads for MSVC linking [Lovell] diff --git a/configure.ac b/configure.ac index 201a893e..14424b8a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # also update the version number in the m4 macros below -AC_INIT([vips], [8.3.1], [vipsip@jiscmail.ac.uk]) +AC_INIT([vips], [8.3.2], [vipsip@jiscmail.ac.uk]) # required for gobject-introspection AC_PREREQ(2.62) @@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4]) # user-visible library versioning m4_define([vips_major_version], [8]) m4_define([vips_minor_version], [3]) -m4_define([vips_micro_version], [1]) +m4_define([vips_micro_version], [2]) m4_define([vips_version], [vips_major_version.vips_minor_version.vips_micro_version]) @@ -38,7 +38,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date` # binary interface changes not backwards compatible?: reset age to 0 LIBRARY_CURRENT=46 -LIBRARY_REVISION=1 +LIBRARY_REVISION=2 LIBRARY_AGE=4 # patched into include/vips/version.h diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 5e913759..8d748507 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -196,8 +196,7 @@ const guint64 vips__image_sizeof_bandformat[] = { guint64 vips_format_sizeof( VipsBandFormat format ) { - g_assert( format >= 0 && - format < VIPS_FORMAT_LAST ); + format = VIPS_CLIP( 0, format, VIPS_FORMAT_DPCOMPLEX ); return( vips__image_sizeof_bandformat[format] ); } diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 3fc640e5..da7bcecd 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -2786,7 +2786,8 @@ vips_image_ispartial( VipsImage *image ) int vips_image_write_prepare( VipsImage *image ) { - g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); + if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) + return( -1 ); if( image->Xsize <= 0 || image->Ysize <= 0 || @@ -3046,7 +3047,8 @@ vips_image_wio_input( VipsImage *image ) { VipsImage *t1; - g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); + if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) + return( -1 ); #ifdef DEBUG_IO printf( "vips_image_wio_input: wio input for %s\n", @@ -3269,8 +3271,9 @@ vips_image_inplace( VipsImage *image ) */ int vips_image_pio_input( VipsImage *image ) -{ - g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); +{ + if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) + return( -1 ); #ifdef DEBUG_IO printf( "vips_image_pio_input: enabling partial input for %s\n", diff --git a/libvips/iofuncs/threadpool.c b/libvips/iofuncs/threadpool.c index 3826177a..c70ec47d 100644 --- a/libvips/iofuncs/threadpool.c +++ b/libvips/iofuncs/threadpool.c @@ -692,7 +692,7 @@ vips_threadpool_new( VipsImage *im ) VipsThreadpool *pool; int tile_width; int tile_height; - int n_tiles; + gint64 n_tiles; int n_lines; /* Allocate and init new thread block. @@ -716,7 +716,9 @@ vips_threadpool_new( VipsImage *im ) * the number of threads we create. */ vips_get_tile_size( im, &tile_width, &tile_height, &n_lines ); - n_tiles = (1 + im->Xsize / tile_width) * (1 + im->Ysize / tile_height); + n_tiles = (1 + (gint64) im->Xsize / tile_width) * + (1 + (gint64) im->Ysize / tile_height); + n_tiles = VIPS_CLIP( 0, n_tiles, MAX_THREADS ); pool->nthr = VIPS_MIN( pool->nthr, n_tiles ); /* Attach tidy-up callback.