From b6276dd44d632c3d4625a78640739db1ca2b075e Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 23 Sep 2020 15:39:33 +0100 Subject: [PATCH] heifload: simplify is_a check of first 4 bytes Allow multiples of 4, up to 32, as chunk length --- libvips/foreign/heifload.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index b0be63a2..90532d03 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -260,14 +260,11 @@ 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 ) + const guint32 chunk_len = GUINT_FROM_BE( *buf ); + if( chunk_len > 32 || chunk_len % 4 != 0 ) return ( 0 ); for( i = 0; i < VIPS_NUMBER( heif_magic ); i++ )