From 20cee5d0415c4915c7427ef3bfd5ccb9fdd1c50b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 28 Nov 2019 09:59:30 +0000 Subject: [PATCH] block metadata changes on shared images If images are shared (ref count > 1), block changes to the set of metadata items on the image. These can cause crashes in highly threaded programs. See https://github.com/lovell/sharp/issues/1986 --- libvips/iofuncs/header.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 6b971cd3..449bca95 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -1020,6 +1020,13 @@ vips_image_set( VipsImage *image, const char *name, GValue *value ) g_assert( name ); g_assert( value ); + /* If this image is shared, block metadata changes. + */ + if( G_OBJECT( image )->ref_count > 1 ) { + g_info( "can't set metadata \"%s\" on shared image", name ); + return; + } + meta_init( image ); (void) meta_new( image, name, value ); @@ -1213,6 +1220,13 @@ vips_image_get_typeof( const VipsImage *image, const char *name ) gboolean vips_image_remove( VipsImage *image, const char *name ) { + /* If this image is shared, block metadata changes. + */ + if( G_OBJECT( image )->ref_count > 1 ) { + g_info( "can't remove metadata \"%s\" on shared image", name ); + return( FALSE ); + } + if( image->meta && g_hash_table_remove( image->meta, name ) ) return( TRUE );