After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 778588 - gnome-todo segfaults when selecting ToDo.txt file
gnome-todo segfaults when selecting ToDo.txt file
Status: RESOLVED FIXED
Product: gnome-todo
Classification: Other
Component: Plugins
unspecified
Other Linux
: High critical
: ---
Assigned To: GNOME To Do maintainer(s)
GNOME To Do maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2017-02-14 03:54 UTC by Mohammed Sadiq
Modified: 2017-04-24 10:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (4.92 KB, patch)
2017-03-05 22:24 UTC, Kevin Lopez
none Details | Review
Patch to segfault (4.95 KB, patch)
2017-03-05 22:41 UTC, Kevin Lopez
none Details | Review
Patch to the segfault (1.84 KB, patch)
2017-03-06 00:16 UTC, Kevin Lopez
none Details | Review
Patch to gtd-plugin-dialog (3.32 KB, patch)
2017-03-06 00:18 UTC, Kevin Lopez
committed Details | Review
Patch to the segfault (8.11 KB, patch)
2017-03-14 04:04 UTC, Kevin Lopez
none Details | Review
Patch to segfault (9.23 KB, patch)
2017-03-20 19:06 UTC, Kevin Lopez
none Details | Review
Pacth (9.44 KB, patch)
2017-03-22 17:22 UTC, Kevin Lopez
rejected Details | Review

Description Mohammed Sadiq 2017-02-14 03:54:18 UTC
How to reproduce:
1. Enable todo.txt plugin.
2. Open settings to todo.txt -> Select some empty Todo.txt file

Result:
gnome-todo segfaults. I believe that an empty Todo.txt corresponds to not having any events added. So empty files should be accepted without segfault (the segfault may be happening for some different reason, but this can be one cause).

Thanks
Comment 1 Mohammed Sadiq 2017-02-16 10:08:34 UTC
Here is the backtrace:

(gdb) bt full
  • #0 __GI_raise
    at ../sysdeps/unix/sysv/linux/raise.c line 58
  • #1 __GI_abort
    at abort.c line 89
  • #2 __libc_message
    at ../sysdeps/posix/libc_fatal.c line 175
  • #3 malloc_printerr
  • #4 _int_free
    at malloc.c line 3902
  • #5 gtd_provider_todo_txt_finalize
    at /home/sadiq/jhbuild/checkout/gnome-todo/plugins/todo-txt/gtd-provider-todo-txt.c line 1048
  • #6 g_object_unref
    at /home/sadiq/jhbuild/checkout/glib/gobject/gobject.c line 3185
  • #7 g_value_unset
    at /home/sadiq/jhbuild/checkout/glib/gobject/gvalue.c line 275
  • #8 g_signal_emit_valist
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3420
  • #9 g_signal_emit_by_name
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3487
  • #10 gtd_plugin_todo_txt_source_changed_cb
    at /home/sadiq/jhbuild/checkout/gnome-todo/plugins/todo-txt/gtd-plugin-todo-txt.c line 306
  • #11 g_closure_invoke
    at /home/sadiq/jhbuild/checkout/glib/gobject/gclosure.c line 804
  • #12 signal_emit_unlocked_R
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3635
  • #13 g_signal_emit_valist
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3391
  • #14 g_signal_emit_by_name
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3487
  • #15 list_row_activated
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkfilechooserwidget.c line 7876
  • #16 list_button_press_event_cb
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkfilechooserwidget.c line 2436
  • #17 _gtk_marshal_BOOLEAN__BOXED
    at gtkmarshalers.c line 86
  • #18 g_closure_invoke
    at /home/sadiq/jhbuild/checkout/glib/gobject/gclosure.c line 804
  • #19 signal_emit_unlocked_R
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3635
  • #20 g_signal_emit_valist
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3401
  • #21 g_signal_emit
    at /home/sadiq/jhbuild/checkout/glib/gobject/gsignal.c line 3447
  • #22 gtk_widget_event_internal
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkwidget.c line 7723
  • #23 propagate_event_up
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkmain.c line 2568
  • #24 propagate_event
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkmain.c line 2670
  • #25 gtk_main_do_event
    at /home/sadiq/jhbuild/checkout/gtk+-3/gtk/gtkmain.c line 1901
  • #26 _gdk_event_emit
    at /home/sadiq/jhbuild/checkout/gtk+-3/gdk/gdkevents.c line 73
  • #27 gdk_event_source_dispatch
    at /home/sadiq/jhbuild/checkout/gtk+-3/gdk/x11/gdkeventsource.c line 367
  • #28 g_main_dispatch
    at /home/sadiq/jhbuild/checkout/glib/glib/gmain.c line 3203
  • #29 g_main_context_dispatch
    at /home/sadiq/jhbuild/checkout/glib/glib/gmain.c line 3856
  • #30 g_main_context_iterate
    at /home/sadiq/jhbuild/checkout/glib/glib/gmain.c line 3929
  • #31 g_main_context_iteration
    at /home/sadiq/jhbuild/checkout/glib/glib/gmain.c line 3990
  • #32 g_application_run
    at /home/sadiq/jhbuild/checkout/glib/gio/gapplication.c line 2381
  • #33 main
    at /home/sadiq/jhbuild/checkout/gnome-todo/src/main.c line 41


Thanks
Comment 2 Kevin Lopez 2017-03-05 19:42:01 UTC
(In reply to Mohammed Sadiq from comment #0)

> gnome-todo segfaults. I believe that an empty Todo.txt corresponds to not
> having any events added. So empty files should be accepted without segfault
> (the segfault may be happening for some different reason, but this can be
> one cause).
> 
> Thanks

The segfaults it's produced because it's use a g_free() in a object derived from GObject, instead of use g_clear_object() or g_object_unref().

> having any events added. So empty files should be accepted without segfault
> (the segfault may be happening for some different reason, but this can be
> one cause).

I'm not the official developer but as I can see, trying to solve the segfault, an Todo.txt file needs to have a context (eg "@foo"), this context is used to set the title of the todo list.  So It is not possible to load an empty file.

Anyway I think that will be good, add a dialog to allow user  enter a context to an empty file.
Comment 3 Kevin Lopez 2017-03-05 22:24:48 UTC
Created attachment 347280 [details] [review]
Patch

Selecting empty file,causes a notification dialog that informs to the user that he selected an empty file.
Comment 4 Kevin Lopez 2017-03-05 22:41:18 UTC
Created attachment 347281 [details] [review]
Patch to segfault

I forgot free the strings.
Comment 5 Georges Basile Stavracas Neto 2017-03-05 22:58:57 UTC
Review of attachment 347281 [details] [review]:

Thanks for the patch! Besides the specific changes below, I'd like to ask you to split the GtdPluginDialog work in a separate patch.

::: src/gtd-plugin-dialog.c
@@ +49,3 @@
 
+static gboolean
+delete_widget (GtkWidget *dialog,

Rename to 'dialog_deleted'. Also, instead of "GtkWidget *dialog", you can declare "GtdPluginDialog *self" and simplify the code below.

@@ +55,3 @@
+  gtk_stack_set_transition_type (GTK_STACK (GTD_PLUGIN_DIALOG(dialog)->stack), GTK_STACK_TRANSITION_TYPE_NONE);
+  gtk_stack_set_visible_child_name (GTK_STACK (GTD_PLUGIN_DIALOG(dialog)->stack), "list");
+  gtk_widget_hide (GTD_PLUGIN_DIALOG(dialog)->back_button);

After declaring "GtdPluginDialog *self", you don't need all those GTD_PLUGIN_DIALOG() casts.

@@ +58,3 @@
+  gtk_widget_hide (dialog);
+
+{

Use GDK_EVENT_STOP instead of TRUE.
Comment 6 Kevin Lopez 2017-03-06 00:16:52 UTC
Created attachment 347283 [details] [review]
Patch to the segfault
Comment 7 Kevin Lopez 2017-03-06 00:18:51 UTC
Created attachment 347284 [details] [review]
Patch to gtd-plugin-dialog

Hope this time the patch is correct. Regards!
Comment 8 Georges Basile Stavracas Neto 2017-03-06 11:24:17 UTC
Review of attachment 347283 [details] [review]:

One more question

::: plugins/todo-txt/gtd-provider-todo-txt.c
@@ +360,3 @@
+      g_free (msg);
+      g_free (name);
+    }

Now that I'm looking at it, I believe we must support empty files. What's exactly wrong with it being empty?
Comment 9 Georges Basile Stavracas Neto 2017-03-06 11:24:30 UTC
Review of attachment 347284 [details] [review]:

Looks good.
Comment 10 Georges Basile Stavracas Neto 2017-03-06 11:27:58 UTC
Comment on attachment 347284 [details] [review]
Patch to gtd-plugin-dialog

Commited patch for GtdPluginDialog. Waiting for the segfault to be reviewed.
Comment 11 Kevin Lopez 2017-03-14 04:04:55 UTC
Created attachment 347898 [details] [review]
Patch to the segfault

(In reply to Georges Basile Stavracas Neto from comment #10)
> Commited patch for GtdPluginDialog. Waiting for the segfault to be reviewed.
Hope it is ok. Regards!
Comment 12 Kevin Lopez 2017-03-20 19:06:30 UTC
Created attachment 348343 [details] [review]
Patch to segfault
Comment 13 Georges Basile Stavracas Neto 2017-03-22 14:47:23 UTC
Review of attachment 348343 [details] [review]:

Some comments

::: plugins/todo-txt/gtd-plugin-todo-txt.c
@@ +67,3 @@
+  GFile *source_file;
+  GFileOutputStream *output;
+  gchar *buffer;

Sort this by the size of the type, structures coming before native types. Should be like:

GFileOutputStream
GFile
gchar

@@ +76,3 @@
+                             NULL);
+
+  buffer = g_strconcat ("@",context,NULL);

Space after commas

@@ +78,3 @@
+  buffer = g_strconcat ("@",context,NULL);
+  
+  g_output_stream_write (G_OUTPUT_STREAM (output), buffer, strlen(buffer)*sizeof(gchar), NULL, NULL);

One line per parameter, and spaces around the '*'

@@ +109,3 @@
+                                         GTK_RESPONSE_OK,
+                                         TRUE);
+    }

You can write it like:

gtk_dialog_set_response_sensitive (dialog,
                                   GTK_RESPONSE_OK,
                                   text_length > 0);

@@ +114,3 @@
+
+static void
+show_context_dialog (GtdPluginTodoTxt *self, GtdProviderTodoTxt *provider) 

One parameter per line.

@@ +121,3 @@
+  const gchar *context;
+
+  /**Hardcode to obtain the main window **/

Wrong comment style (should be '/* ... */')

@@ +137,3 @@
+  gtk_widget_set_size_request (dialog, 400, 300);
+
+  label = gtk_label_new ("You selected an empty file without a context.\nPlease add a context to the Todo.txt file.");

This label should be translatable.

@@ +405,3 @@
+      show_context_dialog (self, provider);
+    }
+

Don't need the brackets (one-line if()s don't need them)

@@ +429,2 @@
   g_settings_set_string (self->settings,
+                         "file",

What was the change here?

::: plugins/todo-txt/gtd-provider-todo-txt.c
@@ +1139,3 @@
+                                                     G_MAXINT,
+                                                     0,
+                                                     G_PARAM_READABLE));

This should be an unsigned integer (we don't support negative number of lines, right?)
Comment 14 Kevin Lopez 2017-03-22 17:22:47 UTC
Created attachment 348518 [details] [review]
Pacth

Thanks for the review.

Regards!
Comment 15 Georges Basile Stavracas Neto 2017-03-23 01:10:43 UTC
Review of attachment 348518 [details] [review]:

Now that I'm testing the patch, I don't really understand the necessity to show a dialog. Can't the user simply add a new task list?
Comment 16 Kevin Lopez 2017-03-23 02:45:41 UTC
(In reply to Georges Basile Stavracas Neto from comment #15)
> Review of attachment 348518 [details] [review] [review]:
> 
> Now that I'm testing the patch, I don't really understand the necessity to
> show a dialog. Can't the user simply add a new task list?

In my first approach, Gnome Todo only shows a dialog  that warns to the user that add a Todo Txt empty file is not allowed. And you said in the comment 8 that we have to support add empty files. 

The todo txt plugin sets as name of the list, the task's context, so If we have to support empty files, a context is necessary be writen in the source file, which is the purpose of the dialog.
 
Personally I prefer the first approach.

Regards !
Comment 17 Rohit Kaushik 2017-03-23 12:35:28 UTC
Hi, as far as i can test on my pc we can select empty files, add lists and tasks as with any other todo.txt files. The only problem is when the a line inside the todo.txt describing the task doesn't contain @list-name tag, we ignore such tasks and send user a notification.
Comment 18 Kevin Lopez 2017-03-23 16:01:25 UTC
(In reply to Rohit Kaushik from comment #17)
> Hi, as far as i can test on my pc we can select empty files, add lists and
> tasks as with any other todo.txt files. The only problem is when the a line
> inside the todo.txt describing the task doesn't contain @list-name tag, we
> ignore such tasks and send user a notification.

Hi! Please se the video in the link below. The video is so big so I can't uploaded as attachment.

http://kevlopez.com/files/Segfault.webm

Regards!
Comment 19 Rohit Kaushik 2017-03-23 16:15:26 UTC
Hey, thanks for uploading the video. Can you obtain the backtrace after you get  segfault and upload it .
Comment 20 Kevin Lopez 2017-03-23 16:18:35 UTC
(In reply to Rohit Kaushik from comment #19)
> Hey, thanks for uploading the video. Can you obtain the backtrace after you
> get  segfault and upload it .

The backtrace is in the comment 1 and the explanation of why happens is in the comment 3.

Regards !
Comment 21 Kevin Lopez 2017-03-23 16:23:07 UTC
(In reply to Kevin Lopez from comment #20)
> (In reply to Rohit Kaushik from comment #19)
> > Hey, thanks for uploading the video. Can you obtain the backtrace after you
> > get  segfault and upload it .
> 
> The backtrace is in the comment 1 and the explanation of why happens is in
> the comment 3.
> 
> Regards !

Correction: the explanation is in the comment 2.
Comment 22 Georges Basile Stavracas Neto 2017-04-24 10:44:22 UTC
Review of attachment 348518 [details] [review]:

I'll mark this patch as 'rejected', for it is fixed in master already. Thanks for the efforts.
Comment 23 Georges Basile Stavracas Neto 2017-04-24 10:45:29 UTC
I can't reproduce this issue anymore. Besides that, since Todo.txt is not enabled by default anymore, this is not a blocker bug.

Closing as RESOLVED FIXED, and lowering the priority.