[gimp] app: do not depend on returned image for successful file_open_with_display().



commit 5df4875c88371884e9bce7d62deabcb342ba14e1
Author: Jehan <jehan girinstud io>
Date:   Tue Oct 11 23:19:18 2022 +0200

    app: do not depend on returned image for successful file_open_with_display().
    
    We may return GIMP_PDB_SUCCESS with no image for generic file procedure, such as
    is the case with .gex extension files.
    file_open_image() already sanitizes the status returned by the plug-in, so at
    this point, we should trust the returned status.
    
    This fixes a crash when loading .gex files (GIMP_PDB_SUCCESS status yet a NULL
    error).

 app/widgets/gimptoolbox-dnd.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/app/widgets/gimptoolbox-dnd.c b/app/widgets/gimptoolbox-dnd.c
index 4a178886e9..91c0155de8 100644
--- a/app/widgets/gimptoolbox-dnd.c
+++ b/app/widgets/gimptoolbox-dnd.c
@@ -154,17 +154,26 @@ gimp_toolbox_drop_uri_list (GtkWidget *widget,
   for (list = uri_list; list; list = g_list_next (list))
     {
       GFile             *file = g_file_new_for_uri (list->data);
-      GimpImage         *image;
       GimpPDBStatusType  status;
       GError            *error = NULL;
 
-      image = file_open_with_display (context->gimp, context, NULL,
-                                      file, FALSE,
-                                      G_OBJECT (gimp_widget_get_monitor (widget)),
-                                      &status, &error);
+      file_open_with_display (context->gimp, context, NULL,
+                              file, FALSE,
+                              G_OBJECT (gimp_widget_get_monitor (widget)),
+                              &status, &error);
 
-      if (! image && status != GIMP_PDB_CANCEL)
+      if (status != GIMP_PDB_CANCEL && status != GIMP_PDB_SUCCESS)
         {
+          /* file_open_image() took care of always having a filled error when
+           * the status is neither CANCEL nor SUCCESS (and to transform a
+           * wrongful success without a returned image into an EXECUTION_ERROR).
+           *
+           * In some case, we may also have a SUCCESS without an image, when the
+           * file procedure is a `generic_file_proc` (e.g. for a .gex extension
+           * file). So we should not rely on having a returned image or not.
+           * Once again, sanitizing the returned status is handled by
+           * file_open_image().
+           */
           gimp_message (context->gimp, G_OBJECT (widget), GIMP_MESSAGE_ERROR,
                         _("Opening '%s' failed:\n\n%s"),
                         gimp_file_get_utf8_name (file), error->message);


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