From 8c4abf7c4206213d4656929127a774c4235f1f52 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 6 Mar 2017 10:07:31 +0000 Subject: [PATCH] allow vips images to have a missing XML block --- TODO | 8 +++++--- libvips/iofuncs/vips.c | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 721da8bb..4231971d 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,13 @@ - - - VIPS_META_SEQUENTIAL will be saved to vips files, then loaded back again argh we need to set a value that can't be saved - do we need a seq cache for reducev as well? we could have up to a 3x + maybe a NULL boxed pointer? + + looks like vips_image_set_area(im, "poop", NULL, NULL); might work + +- do we need a seq cache for reducev as well? we could have up to a 3x reduction there diff --git a/libvips/iofuncs/vips.c b/libvips/iofuncs/vips.c index c18c9742..8f3f4088 100644 --- a/libvips/iofuncs/vips.c +++ b/libvips/iofuncs/vips.c @@ -464,6 +464,9 @@ parser_read_fd( XML_Parser parser, int fd ) const int chunk_size = 1024; ssize_t bytes_read; + ssize_t len; + + bytes_read = 0; do { void *buf; @@ -473,19 +476,25 @@ parser_read_fd( XML_Parser parser, int fd ) "%s", _( "unable to allocate read buffer" ) ); return( -1 ); } - bytes_read = read( fd, buf, chunk_size ); - if( bytes_read == (ssize_t) -1 ) { + len = read( fd, buf, chunk_size ); + if( len == (ssize_t) -1 ) { vips_error( "VipsImage", "%s", _( "read error while fetching XML" ) ); return( -1 ); } - if( !XML_ParseBuffer( parser, bytes_read, bytes_read == 0 ) ) { - vips_error( "VipsImage", - "%s", _( "XML parse error" ) ); + /* Allow missing XML block. + */ + if( bytes_read == 0 && + len == 0 ) + break; + bytes_read += len; + + if( !XML_ParseBuffer( parser, len, len == 0 ) ) { + vips_error( "VipsImage", "%s", _( "XML parse error" ) ); return( -1 ); } - } while( bytes_read > 0 ); + } while( len > 0 ); return( 0 ); } @@ -993,7 +1002,8 @@ vips_image_open_input( VipsImage *image ) * harmless. */ if( readhist( image ) ) { - g_warning( _( "error reading XML: %s" ), vips_error_buffer() ); + g_warning( _( "error reading vips image metadata: %s" ), + vips_error_buffer() ); vips_error_clear(); }