[gimp/gimp-2-10] plug-ins: fix #7408 metadata-editor plugin cashing when saving metadata



commit a9867d020aa6e79dd5866890291eb4b821b157f4
Author: Jacob Boerema <jgboerema gmail com>
Date:   Sun Oct 24 13:38:06 2021 -0400

    plug-ins: fix #7408 metadata-editor plugin cashing when saving metadata
    
    When writing metadata in the metadata-editor it did not check for empty
    values. In combination with gexiv2 0.14.0 (which doesn't check in this
    specific case for an empty list of gchar **) and trying to set a non
    repeatable Iptc tag (Iptc.Application2.Headline) using
    gexiv2_metadata_set_tag_multiple we get a crash.
    
    This fix checks first for a non empty value before trying to save the
    metadata tag.
    Since the code is very similar also implemented this check for the Xmp
    tags in addition to the Iptc and simplified some duplicate code.
    
    (cherry picked from commit 6eba73e714067cd5573844163ade960251e21870)

 plug-ins/metadata/metadata-editor.c | 111 +++++++++++++++++++-----------------
 1 file changed, 59 insertions(+), 52 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index 6d15f3a407..87a2e87098 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -4269,77 +4269,84 @@ metadata_editor_write_callback (GtkWidget  *dialog,
 
           text = gtk_text_buffer_get_text (buffer, &start, &end, TRUE);
 
-          if (default_metadata_tags[i].xmp_type == GIMP_XMP_TEXT ||
-              default_metadata_tags[i].xmp_type == GIMP_XMP_NONE)
+          gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
+                                     default_metadata_tags[i].tag);
+
+          if (text && *text)
             {
-              gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
-                                         default_metadata_tags[i].tag);
-              gexiv2_metadata_set_xmp_tag_struct (GEXIV2_METADATA (g_metadata),
-                                                  default_metadata_tags[i].tag,
-                                                  GEXIV2_STRUCTURE_XA_NONE);
-              if (! gexiv2_metadata_set_tag_string (GEXIV2_METADATA (g_metadata),
-                                                    default_metadata_tags[i].tag,
-                                                    text))
+              if (default_metadata_tags[i].xmp_type == GIMP_XMP_TEXT ||
+                  default_metadata_tags[i].xmp_type == GIMP_XMP_NONE)
                 {
-                  set_tag_failed (default_metadata_tags[i].tag);
+                  gexiv2_metadata_set_xmp_tag_struct (GEXIV2_METADATA (g_metadata),
+                                                      default_metadata_tags[i].tag,
+                                                      GEXIV2_STRUCTURE_XA_NONE);
+                  if (! gexiv2_metadata_set_tag_string (GEXIV2_METADATA (g_metadata),
+                                                        default_metadata_tags[i].tag,
+                                                        text))
+                    {
+                      set_tag_failed (default_metadata_tags[i].tag);
+                    }
                 }
-            }
-          else
-            {
-              gchar **multi;
+              else
+                {
+                  gchar **multi;
 
-              gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
-                                         default_metadata_tags[i].tag);
+                  gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
+                                             default_metadata_tags[i].tag);
 
-              /* We have one value per line. */
-              multi = g_strsplit (text, "\n", 0);
+                  /* We have one value per line. */
+                  multi = g_strsplit (text, "\n", 0);
 
-              if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
-                                                      default_metadata_tags[i].tag,
-                                                      (const gchar **) multi))
-                {
-                  set_tag_failed (default_metadata_tags[i].tag);
+                  if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
+                                                          default_metadata_tags[i].tag,
+                                                          (const gchar **) multi))
+                    {
+                      set_tag_failed (default_metadata_tags[i].tag);
+                    }
+                  g_strfreev (multi);
                 }
-
-              g_strfreev (multi);
             }
 
             index = default_metadata_tags[i].other_tag_index;
             if (index > -1)
               {
-                gchar **multi;
-
                 gexiv2_metadata_clear_tag (GEXIV2_METADATA (g_metadata),
                                            equivalent_metadata_tags[index].tag);
-                if (! strcmp ("multi", equivalent_metadata_tags[index].mode))
+
+                if (text && *text)
                   {
-                    multi = g_strsplit (text, "\n", 0);
-                    if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
-                                                            equivalent_metadata_tags[index].tag,
-                                                            (const gchar **) multi))
+                    if (! strcmp ("multi", equivalent_metadata_tags[index].mode))
                       {
-                        set_tag_failed (equivalent_metadata_tags[index].tag);
-                      }
+                        gchar **multi;
 
-                    g_strfreev (multi);
-                  }
-                else if (! strcmp ("single", equivalent_metadata_tags[index].mode))
-                  {
-                    /* Convert from multiline to single line: keep the \n and just add the whole text. */
-                    if (*text &&
-                        ! gexiv2_metadata_set_tag_string (GEXIV2_METADATA (g_metadata),
-                                                          equivalent_metadata_tags[index].tag,
-                                                          text))
+                        multi = g_strsplit (text, "\n", 0);
+
+                        if (! gexiv2_metadata_set_tag_multiple (GEXIV2_METADATA (g_metadata),
+                                                                equivalent_metadata_tags[index].tag,
+                                                                (const gchar **) multi))
+                          {
+                            set_tag_failed (equivalent_metadata_tags[index].tag);
+                          }
+
+                        g_strfreev (multi);
+                      }
+                    else if (! strcmp ("single", equivalent_metadata_tags[index].mode))
                       {
-                        set_tag_failed (equivalent_metadata_tags[index].tag);
+                        /* Convert from multiline to single line: keep the \n and just add the whole text. */
+                        if (! gexiv2_metadata_set_tag_string (GEXIV2_METADATA (g_metadata),
+                                                              equivalent_metadata_tags[index].tag,
+                                                              text))
+                          {
+                            set_tag_failed (equivalent_metadata_tags[index].tag);
+                          }
+                      }
+                    else
+                      {
+                        g_warning ("Copying from multiline tag %s to %s tag %s not implemented!",
+                                   default_metadata_tags[i].tag,
+                                   equivalent_metadata_tags[index].mode,
+                                   equivalent_metadata_tags[index].tag);
                       }
-                  }
-                else
-                  {
-                    g_warning ("Copying from multiline tag %s to %s tag %s not implemented!",
-                               default_metadata_tags[i].tag,
-                               equivalent_metadata_tags[index].mode,
-                               equivalent_metadata_tags[index].tag);
                   }
               }
 


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