From 553eb73965e4d66ae0de84e9d0a035cb48170dac Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 22 Sep 2020 21:19:53 +0100 Subject: [PATCH 1/2] Verify ISO/3GPP2 signature in heifload is_a check --- libvips/foreign/heifload.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index 646f2a93..a219ee5b 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -260,9 +260,15 @@ static const char *heif_magic[] = { static int vips_foreign_load_heif_is_a( const char *buf, int len ) { + static unsigned char iso[4] = { 0, 0, 0, 24 }; + static unsigned char three_gp[4] = { 0, 0, 0, 32 }; + if( len >= 12 ) { int i; + if ( memcmp( buf, iso, 4 ) != 0 && memcmp( buf, three_gp, 4 ) != 0 ) + return ( 0 ); + for( i = 0; i < VIPS_NUMBER( heif_magic ); i++ ) if( strncmp( buf + 4, heif_magic[i], 8 ) == 0 ) return( 1 ); From e4b711a358c3df0dc5b6f7a4a0053c761c9db5ad Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 23 Sep 2020 08:13:52 +0100 Subject: [PATCH 2/2] better heif signature detection --- ChangeLog | 1 + libvips/foreign/heifload.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34a9525b..fb59284e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - dzsave in iiif mode could set info.json dimensions off by one [Linden6] - pdfload allows dpi and scale to both be set [le0daniel] - allow gaussblur sigma zero, meaning no blur +- better heif signature detection [lovell] 9/8/20 started 8.10.1 - fix markdown -> xml conversion in doc generation diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index a219ee5b..b0be63a2 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -254,7 +254,7 @@ static const char *heif_magic[] = { * * enum heif_filetype_result result = heif_check_filetype( buf, 12 ); * - * but it's very conservative and seems to be missing some of the Noka hief + * but it's very conservative and seems to be missing some of the Nokia hief * types. */ static int @@ -266,7 +266,8 @@ vips_foreign_load_heif_is_a( const char *buf, int len ) if( len >= 12 ) { int i; - if ( memcmp( buf, iso, 4 ) != 0 && memcmp( buf, three_gp, 4 ) != 0 ) + if( memcmp( buf, iso, 4 ) != 0 && + memcmp( buf, three_gp, 4 ) != 0 ) return ( 0 ); for( i = 0; i < VIPS_NUMBER( heif_magic ); i++ )