Skip to content

Commit 1fc01c0

Browse files
authored
exif: ensure prefix is present before parsing (#3100)
Newer Apple devices are creating EXIF without this however libexif still requires it due to JPEG/JFIF/APP1 marker heritage.
1 parent e83468e commit 1fc01c0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- improve rules for 16-bit heifsave [johntrunc]
33
- improve libspng pallette write [kleisauke]
44
- improve libspng pallette sort [DarthSim]
5+
- ensure EXIF has prefix before parsing [lovell]
56

67
5/9/22 started 8.13.2
78
- in dzsave, add add missing include directive for errno/EEXIST [kleisauke]

libvips/foreign/exif.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,17 @@ vips_exif_load_data_without_fix( const void *data, size_t length )
178178
}
179179

180180
exif_data_unset_option( ed, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION );
181-
exif_data_load_data( ed, data, length );
181+
if( !vips_isprefix( "Exif", (char *) data ) ) {
182+
/* Ensure "Exif" prefix as loaders may not provide it.
183+
*/
184+
void* data_with_prefix;
185+
data_with_prefix = g_malloc0( length + 6 );
186+
memcpy( data_with_prefix, "Exif\0\0", 6 );
187+
memcpy( data_with_prefix + 6, data, length );
188+
exif_data_load_data( ed, data_with_prefix, length + 6 );
189+
g_free( data_with_prefix );
190+
} else
191+
exif_data_load_data( ed, data, length );
182192

183193
return( ed );
184194
}
@@ -1391,7 +1401,7 @@ vips__exif_update( VipsImage *image )
13911401
(void *) &data, &length ) )
13921402
return( -1 );
13931403

1394-
if( !(ed = exif_data_new_from_data( data, length )) )
1404+
if( !(ed = vips_exif_load_data_without_fix( data, length )) )
13951405
return( -1 );
13961406
}
13971407
else {
@@ -1401,12 +1411,13 @@ vips__exif_update( VipsImage *image )
14011411
EXIF_DATA_OPTION_FOLLOW_SPECIFICATION );
14021412
exif_data_set_data_type( ed, EXIF_DATA_TYPE_COMPRESSED );
14031413
exif_data_set_byte_order( ed, EXIF_BYTE_ORDER_INTEL );
1404-
1405-
/* Create the mandatory EXIF fields with default data.
1406-
*/
1407-
exif_data_fix( ed );
14081414
}
14091415

1416+
/* Make sure all required fields are there before we attach the vips
1417+
* metadata.
1418+
*/
1419+
exif_data_fix( ed );
1420+
14101421
/* Update EXIF tags from the image metadata.
14111422
*/
14121423
vips_exif_update( ed, image );

0 commit comments

Comments
 (0)