[gimp/gimp-2-10] libgimpbase: fix #8025 Slow loading of XCF files...



commit 8c1b71120ef5a902e879b9bb8ea6000650258883
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Apr 4 16:52:10 2022 -0400

    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 cadf48529944d002b395c068043ecdd9100144c7)
    
    # Conflicts:
    #       libgimpbase/gimpmetadata.c

 libgimpbase/gimpmetadata.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index cb14271805..8c490ce062 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]