From 02095763c9920b997d171f66eab616980ccd75fe Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 6 Jul 2013 11:51:34 +0100 Subject: [PATCH] null-terminate exif strings libexif strings are not null-terminated, add a \0 before adding to the vips image thanks Mike --- ChangeLog | 1 + libvips/foreign/jpeg2vips.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4e3c475..f3acde07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 3/7/13 started 7.34.2 - lower priority for Matlab load to reduce segvs from Mat_Open(), thanks Michael +- null-terminate libexif strings, thanks Mike 28/6/13 started 7.34.1 - fix morphological operators on non-uchar images diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 84c90d8b..4541f671 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -53,6 +53,8 @@ * 21/11/12 * - don't insist exif must have data * - attach IPCT data (app13), thanks Gary + * 6/7/13 + * - null-terminate exif strings, thanks Mike */ /* @@ -407,8 +409,16 @@ vips_exif_to_s( ExifData *ed, ExifEntry *entry, VipsBuf *buf ) ExifSRational srv; char txt[256]; - if( entry->format == EXIF_FORMAT_ASCII ) - vips_buf_appendf( buf, "%s ", entry->data ); + if( entry->format == EXIF_FORMAT_ASCII ) { + /* libexif does not null-terminate strings. Copy out and add + * the \0 ourselves. + */ + int len = VIPS_MIN( 254, entry->size ); + + memcpy( txt, entry->data, len ); + txt[len] = '\0'; + vips_buf_appendf( buf, "%s ", txt ); + } else if( entry->components < 10 && !vips_exif_get_int( ed, entry, 0, &iv ) ) { for( i = 0; i < entry->components; i++ ) {