From d739a240eb701acb2dcf5c1a962488915fa0edee Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 14 May 2013 09:38:59 +0100 Subject: [PATCH] fix a segv with icc import/export would segv for very wide images --- ChangeLog | 3 +++ configure.ac | 6 +++--- libvips/colour/icc_transform.c | 34 ++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff3924c4..087cd987 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +14/5/13 started 7.32.4 +- icc import and export could segv on very wide images + 16/4/13 started 7.32.3 - rename GETTEXT_PACKAGE as vips7.32 to help Debian (thanks Jay) - added "persistent" option to tilecache diff --git a/configure.ac b/configure.ac index cb1c9ae4..f898c366 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # also update the version number in the m4 macros below -AC_INIT([vips], [7.32.3], [vipsip@jiscmail.ac.uk]) +AC_INIT([vips], [7.32.4], [vipsip@jiscmail.ac.uk]) # required for gobject-introspection AC_PREREQ(2.62) @@ -17,7 +17,7 @@ AC_CONFIG_MACRO_DIR([m4]) # user-visible library versioning m4_define([vips_major_version], [7]) m4_define([vips_minor_version], [32]) -m4_define([vips_micro_version], [3]) +m4_define([vips_micro_version], [4]) m4_define([vips_version], [vips_major_version.vips_minor_version.vips_micro_version]) @@ -37,7 +37,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date` # binary interface changes not backwards compatible?: reset age to 0 LIBRARY_CURRENT=34 -LIBRARY_REVISION=1 +LIBRARY_REVISION=2 LIBRARY_AGE=3 # patched into include/vips/version.h diff --git a/libvips/colour/icc_transform.c b/libvips/colour/icc_transform.c index 0f267e93..39b32385 100644 --- a/libvips/colour/icc_transform.c +++ b/libvips/colour/icc_transform.c @@ -22,6 +22,8 @@ * - import and export cast @in to an appropriate format for you * 25/9/12 * - redo as a class + * 14/5/13 + * - import and export would segv on very wide images */ /* @@ -458,15 +460,18 @@ vips_icc_import_line( VipsColour *colour, { VipsIcc *icc = (VipsIcc *) colour; - VipsPel *p = (VipsPel *) in[0]; - float *q = (float *) out; + VipsPel *p; + float *q; + int i; /* Buffer of encoded 16-bit pixels we transform. */ guint16 encoded[3 * PIXEL_BUFFER_SIZE]; - while( width > 0 ) { - const int chunk = VIPS_MIN( width, PIXEL_BUFFER_SIZE ); + p = (VipsPel *) in[0]; + q = (float *) out; + for( i = 0; i < width; i += PIXEL_BUFFER_SIZE ) { + const int chunk = VIPS_MIN( width - i, PIXEL_BUFFER_SIZE ); #ifdef HAVE_LCMS2 cmsDoTransform( icc->trans, p, encoded, chunk ); @@ -478,9 +483,8 @@ vips_icc_import_line( VipsColour *colour, decode_lab( encoded, q, chunk ); - p += chunk * VIPS_IMAGE_SIZEOF_PEL( colour->out ); - q += chunk * 3; - width -= chunk; + p += PIXEL_BUFFER_SIZE * VIPS_IMAGE_SIZEOF_PEL( colour->in[0] ); + q += PIXEL_BUFFER_SIZE * 3; } } @@ -635,15 +639,18 @@ vips_icc_export_line( VipsColour *colour, { VipsIcc *icc = (VipsIcc *) colour; - float *p = (float *) in[0]; - VipsPel *q = (VipsPel *) out; + float *p; + VipsPel *q; + int x; /* Buffer of encoded 16-bit pixels we transform. */ guint16 encoded[3 * PIXEL_BUFFER_SIZE]; - while( width > 0 ) { - const int chunk = VIPS_MIN( width, PIXEL_BUFFER_SIZE ); + p = (float *) in[0]; + q = (VipsPel *) out; + for( x = 0; x < width; x += PIXEL_BUFFER_SIZE ) { + const int chunk = VIPS_MIN( width - x, PIXEL_BUFFER_SIZE ); encode_lab( p, encoded, chunk ); @@ -655,9 +662,8 @@ vips_icc_export_line( VipsColour *colour, g_mutex_unlock( icc->lock ); #endif - p += chunk * 3; - q += chunk * VIPS_IMAGE_SIZEOF_PEL( colour->out ); - width -= chunk; + p += PIXEL_BUFFER_SIZE * 3; + q += PIXEL_BUFFER_SIZE * VIPS_IMAGE_SIZEOF_PEL( colour->out ); } }