libgimpbase: fix #8025 Slow loading of XCF files...
with many Xmp.photoshop.DocumentAncestors tags This is similar to #7464, but in this case the XMP metadata was already included in an XCF image. We check for the occurrence of Xmp.photoshop.DocumentAncestors and stop handling values when there are more than a 1000. It would be easier to just check length for all tags and always ignore when there are more than a 1000 values. But in that case we would need to be sure there are no valid reasons for tags to occur more than a 1000 times. So let's just limit it to this specific tag.
This commit is contained in:
@ -590,6 +590,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
gchar name[1024];
|
gchar name[1024];
|
||||||
gboolean base64;
|
gboolean base64;
|
||||||
|
gboolean excessive_message_shown;
|
||||||
GimpMetadata *metadata;
|
GimpMetadata *metadata;
|
||||||
} GimpMetadataParseData;
|
} GimpMetadataParseData;
|
||||||
|
|
||||||
@ -710,6 +711,24 @@ gimp_metadata_deserialize_text (GMarkupParseContext *context,
|
|||||||
{
|
{
|
||||||
guint length = g_strv_length (values);
|
guint length = g_strv_length (values);
|
||||||
|
|
||||||
|
if (length > 1000 &&
|
||||||
|
! g_strcmp0 (parse_data->name, "Xmp.photoshop.DocumentAncestors"))
|
||||||
|
{
|
||||||
|
/* Issue #8025, see also #7464 Some XCF images can have huge
|
||||||
|
* amounts of this tag, apparently due to a bug in PhotoShop.
|
||||||
|
* This makes deserializing it in the way we currently do
|
||||||
|
* too slow. Until we can change this let's ignore everything
|
||||||
|
* but the first 1000 values when serializing. */
|
||||||
|
|
||||||
|
if (! parse_data->excessive_message_shown)
|
||||||
|
{
|
||||||
|
g_message ("Excessive number of Xmp.photoshop.DocumentAncestors tags found. "
|
||||||
|
"Only keeping the first 1000 values.");
|
||||||
|
parse_data->excessive_message_shown = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
values = g_renew (gchar *, values, length + 2);
|
values = g_renew (gchar *, values, length + 2);
|
||||||
values[length] = value;
|
values[length] = value;
|
||||||
values[length + 1] = NULL;
|
values[length + 1] = NULL;
|
||||||
@ -724,6 +743,7 @@ gimp_metadata_deserialize_text (GMarkupParseContext *context,
|
|||||||
G_STRFUNC, parse_data->name, error->message);
|
G_STRFUNC, parse_data->name, error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_strfreev (values);
|
g_strfreev (values);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -775,6 +795,7 @@ gimp_metadata_deserialize (const gchar *metadata_xml)
|
|||||||
metadata = gimp_metadata_new ();
|
metadata = gimp_metadata_new ();
|
||||||
|
|
||||||
parse_data.metadata = metadata;
|
parse_data.metadata = metadata;
|
||||||
|
parse_data.excessive_message_shown = FALSE;
|
||||||
|
|
||||||
markup_parser.start_element = gimp_metadata_deserialize_start_element;
|
markup_parser.start_element = gimp_metadata_deserialize_start_element;
|
||||||
markup_parser.end_element = gimp_metadata_deserialize_end_element;
|
markup_parser.end_element = gimp_metadata_deserialize_end_element;
|
||||||
|
Reference in New Issue
Block a user