From 94b137d52659742657602d676f0739b2882a6c91 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 18 Jun 2020 11:09:37 +0100 Subject: [PATCH] check return from spng_get_text() it'll fail for no text elements rather than returning 0 --- libvips/foreign/spngload.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libvips/foreign/spngload.c b/libvips/foreign/spngload.c index ac576e65..97863147 100644 --- a/libvips/foreign/spngload.c +++ b/libvips/foreign/spngload.c @@ -192,7 +192,6 @@ vips_foreign_load_png_set_header( VipsForeignLoadPng *png, VipsImage *image ) { double xres, yres; struct spng_iccp iccp; - struct spng_text *text; struct spng_exif exif; struct spng_phys phys; guint32 n_text; @@ -232,16 +231,20 @@ vips_foreign_load_png_set_header( VipsForeignLoadPng *png, VipsImage *image ) vips_image_set_blob_copy( image, VIPS_META_ICC_NAME, iccp.profile, iccp.profile_len ); - spng_get_text( png->ctx, NULL, &n_text ); - text = VIPS_ARRAY( VIPS_OBJECT( png ), n_text, struct spng_text ); - if( !spng_get_text( png->ctx, text, &n_text ) ) { - guint32 i; + if( !spng_get_text( png->ctx, NULL, &n_text ) ) { + struct spng_text *text; - for( i = 0; i < n_text; i++ ) - /* .text is always a null-terminated C string. - */ - vips_foreign_load_png_set_text( image, - i, text[i].keyword, text[i].text ); + text = VIPS_ARRAY( VIPS_OBJECT( png ), + n_text, struct spng_text ); + if( !spng_get_text( png->ctx, text, &n_text ) ) { + guint32 i; + + for( i = 0; i < n_text; i++ ) + /* .text is always a null-terminated C string. + */ + vips_foreign_load_png_set_text( image, + i, text[i].keyword, text[i].text ); + } } if( !spng_get_exif( png->ctx, &exif ) )