[gimp] plug-ins: fix #7464 GIMP stops responding opening metadata on import



commit b2c715b52bf3965f7e866627451d746b19ee5de4
Author: Jacob Boerema <jgboerema gmail com>
Date:   Wed Dec 15 11:54:40 2021 -0500

    plug-ins: fix #7464 GIMP stops responding opening metadata on import
    
    Some images have huge amounts of XMP tag Xmp.photoshop.DocumentAncestors.
    In certain cases more than 100000 values. This is apparently due to a bug
    in certain versions of PhotoShop.
    
    This makes deserializing it in the way we currently do too slow, probably
    because of continuous reallocations after adding each value. Until we can
    change this let's remove everything but the first 1000 values when
    serializing. I think it is very unlikely there are any real cases where
    more than a 1000 ancestor documents are referenced in an image. Testing
    shows that this amount doesn't cause any serious slowdowns.

 libgimpbase/gimpmetadata.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index 800969c627..573127a456 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -856,8 +856,26 @@ gimp_metadata_serialize (GimpMetadata *metadata)
               if (values)
                 {
                   gint  vi;
+                  gint  cnt = 0;
 
-                  for (vi = 0; values[vi] != NULL; vi++)
+                  if (! g_strcmp0 (xmp_data[i], "Xmp.photoshop.DocumentAncestors"))
+                    {
+                      /* Issue #7464 Some images can have huge amounts of this
+                       * tag (more than 100000 in certain cases), 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 remove everything but the first 1000
+                       * values when serializing. */
+                      cnt = g_strv_length (values);
+
+                      if (cnt > 1000)
+                        {
+                          g_message ("Excessive number of Xmp.photoshop.DocumentAncestors tags found: %d. "
+                                     "Only keeping the first 1000 values.", cnt);
+                        }
+                    }
+
+                  for (vi = 0; values[vi] != NULL && (cnt <= 1000 || vi < 1000); vi++)
                     {
                       escaped = gimp_metadata_escape (xmp_data[i], values[vi], &base64);
                       gimp_metadata_append_tag (string, xmp_data[i], escaped, base64);


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