From: Lutz M. <lu...@us...> - 2008-02-16 19:11:47
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv25655/libexif Modified Files: exif-content.c exif-data.c Log Message: 2008-02-16 Lutz Mueller <lu...@us...> Jan Patera <pa...@pi...> 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. Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.108 retrieving revision 1.109 diff -u -p -d -r1.108 -r1.109 --- exif-data.c 14 Feb 2008 19:20:21 -0000 1.108 +++ exif-data.c 16 Feb 2008 19:11:40 -0000 1.109 @@ -234,6 +234,7 @@ exif_data_save_data_entry (ExifData *dat { unsigned int doff, s; unsigned char *t; + unsigned int ts; if (!data || !data->priv) return; @@ -269,21 +270,22 @@ exif_data_save_data_entry (ExifData *dat 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'; @@ -479,6 +481,7 @@ exif_data_save_data_content (ExifData *d 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; @@ -523,13 +526,14 @@ exif_data_save_data_content (ExifData *d * 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, @@ -628,14 +632,15 @@ exif_data_save_data_content (ExifData *d 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; Index: exif-content.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-content.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -p -d -r1.23 -r1.24 --- exif-content.c 14 Feb 2008 19:20:21 -0000 1.23 +++ exif-content.c 16 Feb 2008 19:11:40 -0000 1.24 @@ -168,12 +168,14 @@ exif_content_remove_entry (ExifContent * /* 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 * |