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.

(cherry picked from commit cadf485299)

# Conflicts:
#	libgimpbase/gimpmetadata.c
This commit is contained in:
Jacob Boerema
2022-04-04 16:52:10 -04:00
parent 6f44527206
commit 8c1b71120e

View File

@ -551,6 +551,7 @@ typedef struct
{
gchar name[1024];
gboolean base64;
gboolean excessive_message_shown;
GimpMetadata *metadata;
} GimpMetadataParseData;
@ -664,13 +665,32 @@ gimp_metadata_deserialize_text (GMarkupParseContext *context,
{
guint length = g_strv_length (values);
values = g_renew (gchar *, values, length + 2);
values[length] = value;
values[length + 1] = NULL;
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. */
gexiv2_metadata_set_tag_multiple (g2_metadata,
parse_data->name,
(const gchar **) values);
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[length] = value;
values[length + 1] = NULL;
gexiv2_metadata_set_tag_multiple (g2_metadata,
parse_data->name,
(const gchar **) values);
}
g_strfreev (values);
}
else
@ -716,6 +736,7 @@ gimp_metadata_deserialize (const gchar *metadata_xml)
metadata = gimp_metadata_new ();
parse_data.metadata = metadata;
parse_data.excessive_message_shown = FALSE;
markup_parser.start_element = gimp_metadata_deserialize_start_element;
markup_parser.end_element = gimp_metadata_deserialize_end_element;