diff --git a/ChangeLog b/ChangeLog index b4c51a04a2..f2325bb2d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-07-05 Sven Neumann + + * app/xcf/xcf-read.c (xcf_read_int32) (xcf_read_int8): return the + number of bytes that have been read from the file. + + * app/xcf/xcf-load.c (xcf_load_prop): return FALSE when reading fails. + 2007-07-05 Sven Neumann * tools/pdbgen/pdb.pl (arg_parse): allow the use of constants when diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c index 128c070384..0aa341d3b6 100644 --- a/app/xcf/xcf-load.c +++ b/app/xcf/xcf-load.c @@ -297,7 +297,7 @@ xcf_load_image_props (XcfInfo *info, while (TRUE) { - if (!xcf_load_prop (info, &prop_type, &prop_size)) + if (! xcf_load_prop (info, &prop_type, &prop_size)) return FALSE; switch (prop_type) @@ -381,8 +381,10 @@ xcf_load_image_props (XcfInfo *info, nguides = prop_size / (4 + 1); for (i = 0; i < nguides; i++) { - info->cp += xcf_read_int32 (info->fp, (guint32 *) &position, 1); - info->cp += xcf_read_int8 (info->fp, (guint8 *) &orientation, 1); + info->cp += xcf_read_int32 (info->fp, + (guint32 *) &position, 1); + info->cp += xcf_read_int8 (info->fp, + (guint8 *) &orientation, 1); /* skip -1 guides from old XCFs */ if (position < 0) @@ -617,7 +619,7 @@ xcf_load_layer_props (XcfInfo *info, while (TRUE) { - if (!xcf_load_prop (info, &prop_type, &prop_size)) + if (! xcf_load_prop (info, &prop_type, &prop_size)) return FALSE; switch (prop_type) @@ -715,6 +717,7 @@ xcf_load_layer_props (XcfInfo *info, gimp_item_parasite_attach (GIMP_ITEM (layer), p); gimp_parasite_free (p); } + if (info->cp - base != prop_size) gimp_message (info->gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING, @@ -763,7 +766,7 @@ xcf_load_channel_props (XcfInfo *info, while (TRUE) { - if (!xcf_load_prop (info, &prop_type, &prop_size)) + if (! xcf_load_prop (info, &prop_type, &prop_size)) return FALSE; switch (prop_type) @@ -857,6 +860,7 @@ xcf_load_channel_props (XcfInfo *info, gimp_item_parasite_attach (GIMP_ITEM (*channel), p); gimp_parasite_free (p); } + if (info->cp - base != prop_size) gimp_message (info->gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING, @@ -896,8 +900,16 @@ xcf_load_prop (XcfInfo *info, PropType *prop_type, guint32 *prop_size) { - info->cp += xcf_read_int32 (info->fp, (guint32 *) prop_type, 1); - info->cp += xcf_read_int32 (info->fp, (guint32 *) prop_size, 1); + if (G_UNLIKELY (xcf_read_int32 (info->fp, (guint32 *) prop_type, 1) != 4)) + return FALSE; + + info->cp += 4; + + if (G_UNLIKELY (xcf_read_int32 (info->fp, (guint32 *) prop_size, 1) != 4)) + return FALSE; + + info->cp += 4; + return TRUE; } diff --git a/app/xcf/xcf-read.c b/app/xcf/xcf-read.c index d2c749ca2a..e846437ca8 100644 --- a/app/xcf/xcf-read.c +++ b/app/xcf/xcf-read.c @@ -34,11 +34,11 @@ xcf_read_int32 (FILE *fp, guint32 *data, gint count) { - guint total = count; + guint total = 0; if (count > 0) { - xcf_read_int8 (fp, (guint8 *) data, count * 4); + total += xcf_read_int8 (fp, (guint8 *) data, count * 4); while (count--) { @@ -47,7 +47,7 @@ xcf_read_int32 (FILE *fp, } } - return total * 4; + return total; } guint @@ -63,15 +63,17 @@ xcf_read_int8 (FILE *fp, guint8 *data, gint count) { - guint total = count; + guint total = 0; while (count > 0) { - gint bytes = fread ((char *) data, sizeof (char), count, fp); + gint bytes = fread ((char *) data, sizeof (char), count, fp); if (bytes <= 0) /* something bad happened */ break; + total += bytes; + count -= bytes; data += bytes; }