Skip to content

Commit

Permalink
Fix saving EXIF strings with invalid UTF8 encoding (libvips#3720)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim authored Oct 18, 2023
1 parent c1e4d03 commit 1e12591
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libvips/foreign/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ vips_exif_to_s(ExifData *ed, ExifEntry *entry, VipsBuf *buf)
int iv;
ExifRational rv;
ExifSRational srv;
char txt[256];
char txt[256], *value;

value = g_utf8_make_valid(
exif_entry_get_value(entry, txt, 256), -1);

if (entry->format == EXIF_FORMAT_ASCII) {
/* libexif does not null-terminate strings. Copy out and add
Expand All @@ -306,7 +309,10 @@ vips_exif_to_s(ExifData *ed, ExifEntry *entry, VipsBuf *buf)

memcpy(txt, entry->data, len);
txt[len] = '\0';
vips_buf_appendf(buf, "%s ", txt);

char *utf8 = g_utf8_make_valid(txt, -1);
vips_buf_appendf(buf, "%s ", utf8);
g_free(utf8);
}
else if (entry->components < 10 &&
!vips_exif_get_int(ed, entry, 0, &iv)) {
Expand All @@ -332,14 +338,15 @@ vips_exif_to_s(ExifData *ed, ExifEntry *entry, VipsBuf *buf)
}
}
else
vips_buf_appendf(buf, "%s ",
exif_entry_get_value(entry, txt, 256));
vips_buf_appendf(buf, "%s ", value);

vips_buf_appendf(buf, "(%s, %s, %lu components, %d bytes)",
exif_entry_get_value(entry, txt, 256),
value,
exif_format_get_name(entry->format),
entry->components,
entry->size);

g_free(value);
}

typedef struct _VipsExifParams {
Expand Down

0 comments on commit 1e12591

Please sign in to comment.