From 6a445ea9c8679c169c7cfff85cba44ab775435c6 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 17 May 2016 21:58:52 +0100 Subject: [PATCH] more vips image read fixing thanks AFL! --- ChangeLog | 1 + libvips/iofuncs/header.c | 3 +-- libvips/iofuncs/image.c | 11 +++++++---- libvips/iofuncs/threadpool.c | 6 ++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e487f530..45bfd12e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ felixbuenemann - allow nested [] in CLI args - restore BandFmt on unpremultiply in vipsthumbnail +- more robust vips image reading 15/4/16 started 8.3.1 - rename vips wrapper script, it was still vips-8.2, thanks Benjamin diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 61d5b177..2b5a6aa3 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 bf33c6cc..ced8d367 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.