+2008-02-16 Lutz Mueller <lutz@users.sourceforge.net>
+
+ Jan Patera <patera@pictview.com> spotted a problem with my last fix
+ for #1774591:
+
+ * libexif/exif-content.c: (exif_content_remove_entry) Recover
+ correctly in case of error by remembering the original size of the
+ realloc'ed data.
+ * libexif/exif-data.c: (exif_data_save_data_entry),
+ (exif_data_save_data_content) Same here.
+ * libexif/canon/exif-mnote-data-canon.c:
+ (exif_mnote_data_canon_save), (exif_mnote_data_canon_load) Same here.
+ * libexif/fuji/exif-mnote-data-fuji.c:
+ (exif_mnote_data_fuji_save), (exif_mnote_data_fuji_load) Same here.
+ * libexif/olympus/exif-mnote-data-olympus.c:
+ (exif_mnote_data_olympus_save) Same here.
+
2008-02-15 Lutz Mueller <lutz@users.sourceforge.net>
* Changelog
ExifMnoteDataCanon *n = (ExifMnoteDataCanon *) ne;
unsigned int i, o, s, doff;
unsigned char *t;
+ unsigned int ts;
if (!n || !buf || !buf_size) return;
s = exif_format_get_size (n->entries[i].format) *
n->entries[i].components;
if (s > 4) {
- *buf_size += s;
+ ts = *buf_size + s;
/* Ensure even offsets. Set padding bytes to 0. */
- if (s & 1) *buf_size += 1;
+ if (s & 1) ts += 1;
t = exif_mem_realloc (ne->mem, *buf,
- sizeof (char) * *buf_size);
+ sizeof (char) * ts);
if (!t) return;
*buf = t;
+ *buf_size = ts;
doff = *buf_size - s;
if (s & 1) { doff--; *(*buf + *buf_size - 1) = '\0'; }
exif_set_long (*buf + o, n->order, n->offset + doff);
o = 6 + 2 + n->offset + 12 * i;
if (o + 8 > buf_size) return;
- n->count = i + 1;
t = exif_mem_realloc (ne->mem, n->entries,
sizeof (MnoteCanonEntry) * (i + 1));
if (!t) return;
+ n->count = i + 1;
n->entries = t;
memset (&n->entries[i], 0, sizeof (MnoteCanonEntry));
n->entries[i].tag = exif_get_short (buf + o, n->order);
/* Remove the entry */
memmove (&c->entries[i], &c->entries[i + 1],
sizeof (ExifEntry*) * (c->count - i - 1));
- c->count--;
e->parent = NULL;
exif_entry_unref (e);
t = exif_mem_realloc (c->priv->mem, c->entries,
- sizeof(ExifEntry*) * c->count);
- if (t) c->entries = t;
+ sizeof(ExifEntry*) * (c->count - 1));
+ if (t) {
+ c->entries = t;
+ c->count--;
+ }
}
ExifEntry *
{
unsigned int doff, s;
unsigned char *t;
+ unsigned int ts;
if (!data || !data->priv)
return;
s = exif_format_get_size (e->format) * e->components;
if (s > 4) {
doff = *ds - 6;
- *ds += s;
+ ts = *ds + s;
/*
* According to the TIFF specification,
* the offset must be an even number. If we need to introduce
* a padding byte, we set it to 0.
*/
- if (s & 1)
- (*ds)++;
- t = exif_mem_realloc (data->priv->mem, *d, *ds);
+ if (s & 1)
+ ts++;
+ t = exif_mem_realloc (data->priv->mem, *d, ts);
if (!t) {
- EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds);
+ EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", ts);
return;
}
*d = t;
+ *ds = ts;
exif_set_long (*d + 6 + offset + 8, data->priv->order, doff);
if (s & 1)
*(*d + *ds - 1) = '\0';
unsigned int j, n_ptr = 0, n_thumb = 0;
ExifIfd i;
unsigned char *t;
+ unsigned int ts;
if (!data || !data->priv || !ifd || !d || !ds)
return;
* Allocate enough memory for all entries
* and the number of entries.
*/
- *ds += (2 + (ifd->count + n_ptr + n_thumb) * 12 + 4);
- t = exif_mem_realloc (data->priv->mem, *d, *ds);
+ ts = *ds + (2 + (ifd->count + n_ptr + n_thumb) * 12 + 4);
+ t = exif_mem_realloc (data->priv->mem, *d, ts);
if (!t) {
- EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds);
+ EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", ts);
return;
}
*d = t;
+ *ds = ts;
/* Save the number of entries */
exif_set_short (*d + 6 + offset, data->priv->order,
1);
exif_set_long (*d + 6 + offset + 8, data->priv->order,
*ds - 6);
- *ds += data->size;
- t = exif_mem_realloc (data->priv->mem, *d, *ds);
+ ts = *ds + data->size;
+ t = exif_mem_realloc (data->priv->mem, *d, ts);
if (!t) {
EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData",
- *ds);
+ ts);
return;
}
*d = t;
+ *ds = ts;
memcpy (*d + *ds - data->size, data->data, data->size);
offset += 12;
ExifMnoteDataFuji *n = (ExifMnoteDataFuji *) ne;
unsigned int i, o, s, doff;
unsigned char *t;
+ unsigned int ts;
if (!n || !buf || !buf_size) return;
s = exif_format_get_size (n->entries[i].format) *
n->entries[i].components;
if (s > 4) {
- *buf_size += s;
+ ts = *buf_size + s;
/* Ensure even offsets. Set padding bytes to 0. */
- if (s & 1) *buf_size += 1;
- t = exif_mem_realloc (ne->mem, *buf, *buf_size);
+ if (s & 1) ts += 1;
+ t = exif_mem_realloc (ne->mem, *buf, ts);
if (!t) {
*buf_size = 0;
return;
}
*buf = t;
+ *buf_size = ts;
doff = *buf_size - s;
if (s & 1) { doff--; *(*buf + *buf_size - 1) = '\0'; }
exif_set_long (*buf + o, n->order, doff);
o = datao + 12 * i;
if (datao + 12 > buf_size) return;
- n->count = i + 1;
t = exif_mem_realloc (en->mem, n->entries,
sizeof (MnoteFujiEntry) * (i + 1));
if (!t) return;
+ n->count = i + 1;
n->entries = t;
memset (&n->entries[i], 0, sizeof (MnoteFujiEntry));
n->entries[i].tag = exif_get_short (buf + o, n->order);
ExifMnoteDataOlympus *n = (ExifMnoteDataOlympus *) ne;
unsigned int i, o, s, doff, base = 0, o2 = 6 + 2;
int datao = 0;
+ unsigned char *t;
+ unsigned int ts;
if (!n || !buf || !buf_size) return;
n->entries[i].components;
if (s > 4) {
doff = *buf_size;
- *buf_size += s;
- *buf = exif_mem_realloc (ne->mem, *buf,
- sizeof (char) * *buf_size);
- if (!*buf) return;
+ ts = *buf_size + s;
+ t = exif_mem_realloc (ne->mem, *buf,
+ sizeof (char) * ts);
+ if (!t) return;
+ *buf = t;
+ *buf_size = ts;
exif_set_long (*buf + o, n->order, datao + doff);
} else
doff = o;