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 726390 - Crash when trying to open certain files while the multi edit plugin is active
Crash when trying to open certain files while the multi edit plugin is active
Status: RESOLVED FIXED
Product: gedit-plugins
Classification: Other
Component: General
3.10.x
Other Linux
: Normal critical
: ---
Assigned To: Gedit maintainers
Gedit maintainers
Depends on: 726689
Blocks:
 
 
Reported: 2014-03-15 04:47 UTC by Jean-François Fortin Tam
Modified: 2019-03-23 20:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Make sure text passed to insert_text is null terminated (4.16 KB, patch)
2014-03-19 13:04 UTC, jessevdk@gmail.com
none Details | Review
Make sure text passed to insert_text is null terminated (4.33 KB, patch)
2014-03-19 13:16 UTC, jessevdk@gmail.com
accepted-commit_after_freeze Details | Review

Description Jean-François Fortin Tam 2014-03-15 04:47:57 UTC
If I have the "multi edit" plugin active, gedit will instantly crash if I try to open some files I have, such as "Documents/idées pour condo.markdown" or "Documents/smileys japonais (all japanese emoticons).txt".

This happens both if I try to open the file with ctrl+O or if I run "gedit Documents/the_file".

Here is the backtrace I could get through gdb when opening the markdown file mentioned above (you can see some of the strings through the backtrace...)


(gdb) bt full
  • #0 __GI_raise
    at ../nptl/sysdeps/unix/sysv/linux/raise.c line 56
  • #1 __GI_abort
    at abort.c line 89
  • #2 _g_log_abort
    at gmessages.c line 255
  • #3 g_assertion_message
    at gtestutils.c line 2278
  • #4 g_assertion_message_expr
    at gtestutils.c line 2293
  • #5 _pygi_argument_to_object
    at pygi-argument.c line 1581
  • #6 pygi_signal_closure_marshal
    at pygi-signal-closure.c line 130
  • #7 g_closure_invoke
    at gclosure.c line 777
  • #8 signal_emit_unlocked_R
    at gsignal.c line 3586
  • #9 g_signal_emit_valist
    at gsignal.c line 3330
  • #10 g_signal_emit
    at gsignal.c line 3386
  • #11 gtk_text_buffer_emit_insert
  • #12 gtk_text_buffer_insert
  • #13 validate_and_insert
  • #14 gedit_document_output_stream_write
    at gedit-document-output-stream.c line 974
  • #15 g_output_stream_write
    at goutputstream.c line 211
  • #16 write_file_chunk
    at gedit-document-loader.c line 503
  • #17 async_read_cb
    at gedit-document-loader.c line 610
  • #18 async_ready_callback_wrapper
    at ginputstream.c line 519
  • #19 g_task_return_now
    at gtask.c line 1108
  • #20 complete_in_idle_cb
    at gtask.c line 1117
  • #21 g_main_dispatch
    at gmain.c line 3066
  • #22 g_main_context_dispatch
    at gmain.c line 3642
  • #23 g_main_context_iterate
    at gmain.c line 3713
  • #24 g_main_context_iteration
    at gmain.c line 3774
  • #25 g_application_run
    at gapplication.c line 1635
  • #26 main
    at gedit.c line 68

Comment 1 jessevdk@gmail.com 2014-03-18 08:25:20 UTC
From the trace, this looks like a bug in pygobject rather than gedit. It seems it never even enters the multiedit plugin, but crashes when trying to marshal the string of the insert-text signal. Can you please give some more information on the exact versions of gedit and pygobject installed on your system? I could also not reproduce this, but I'm running gedit 3.8.3 with python gobject 3.10.0.
Comment 2 Jean-François Fortin Tam 2014-03-18 14:29:26 UTC
This is Gedit 3.10.3 + python3-gobject 3.10.2 installed on Fedora 20, 64 bits.
Comment 3 jessevdk@gmail.com 2014-03-18 19:13:21 UTC
Well, I just upgraded to gedit 3.10.4 and pygobject 3.10.2, and I can't reproduce. Since we haven't had any other reports, I'm starting to think along the lines of something being weird on your system. I asked someone else to reproduce, also on fedora, and nope :( If this is a pygobject issue, could you try and see if the same problem occurs with another plugin, for example the snippets plugin should also trigger this.

Are you sure you're not accidentally linking to another version of pygobject somehow?
Comment 4 Jean-François Fortin Tam 2014-03-19 01:04:48 UTC
Yeah, just using the stock versions. But as I mentioned I think this happens only on some files, it must be caused by particular non-english contents... I'll email the file to your gmail address (rather than attaching it to this bug report ;)
Comment 5 jessevdk@gmail.com 2014-03-19 08:02:02 UTC
OK, I can reproduce this now, but only when I try to open those files using ISO-8859-15 encoding. Opening them in UTF-8 seems to not make anything crash. Is that what happens for you as well?
Comment 6 jessevdk@gmail.com 2014-03-19 13:04:46 UTC
Created attachment 272380 [details] [review]
Make sure text passed to insert_text is null terminated
Comment 7 jessevdk@gmail.com 2014-03-19 13:07:14 UTC
I think this patch provides a quickfix for the immediate problem. It should solve more or less all issues, since it ensures all text passed to gtk is properly null terminated. This in turn should allow pygobject to not care about the length argument for the insert-text signal. See also bug #726689 for more details.

The downsides to this patch are that it will do some more allocations in some corner cases, when dealing with invalid text. At least it solves the crash for me.
Comment 8 jessevdk@gmail.com 2014-03-19 13:16:30 UTC
Created attachment 272381 [details] [review]
Make sure text passed to insert_text is null terminated
Comment 9 Paolo Borelli 2014-03-19 13:24:51 UTC
Review of attachment 272381 [details] [review]:

looks good to me, but this bug has been there for a few releases, so I think we do not need to rush it and request a freeze break
Comment 10 Jean-François Fortin Tam 2014-03-19 14:22:13 UTC
> OK, I can reproduce this now, but only when I try to open those files using
> ISO-8859-15 encoding. Opening them in UTF-8 seems to not make anything crash.
> Is that what happens for you as well?

I don't know, in gedit's "open" filechooser I let it to "detect encoding automatically", and this also happens if you open the files from the commandline (gedit ~/Documents/the_document.markdown). I thought everything was unicode these days, at least all files created by gedit. So I'm not sure why gedit would misdetect that markdown file as not being unicode...
Comment 11 jessevdk@gmail.com 2014-03-19 14:28:07 UTC
It should normally try utf-8 first, unless there was a metadata attribute set on it, but that means you'd have to have explicitly opened it once in that encoding (or saved it in that encoding). The bug can also appear when you have a file with windows line endings (i.e. \r\n) which is the case for the two files you sent me.
Comment 12 Paolo Borelli 2014-03-30 14:38:47 UTC
pushed. I am closing this bug since there is the pygobject one tracking the underlying issue
Comment 13 Sébastien Wilmet 2014-06-30 11:54:57 UTC
Jeff or Jesse, do you still have the files to reproduce this bug?

The file loading and saving stuff is being moved to GtkSourceView, and the above patch is not yet applied (I copied the gedit code before).
Comment 14 Sébastien Wilmet 2014-07-03 19:46:19 UTC
I'm trying to reproduce this bug with a code like:

> gchar text[4] = {'a', 'b', 'c', 'd'};
> gtk_text_buffer_insert (buffer, &iter, text, 4);

With the multi-edit plugin modified to always use the text variable in the insert-text signal handler.

And it doesn't crash.

I wanted to reproduce the crash to try to fix it by adding annotations to the insert-text signal like this:

> @text: (array length=len) (element-type uint8): the UTF-8 text to be inserted
> @len: length of the inserted text in bytes
Comment 15 Sébastien Wilmet 2014-07-03 19:49:58 UTC
For example g_file_set_contents() has also a "gchar *" parameter with a length, and it uses the [array length=length][element-type guint8] annotation.
Comment 16 Sébastien Wilmet 2014-07-13 13:39:15 UTC
For the record, to reproduce the crash:

/* The last character is an invalid UTF-8 character. */
gchar text[4] = {'a', 'b', 'c', '\xC0'};
gtk_text_buffer_insert (buffer, &iter, text, 3);

With the insert-text signal connected in Python.

The annotation like g_file_set_contents() helps a little, it avoids the crash, but there is a bug with the text variable in Python:

> Warning: g_value_get_pointer: assertion 'G_VALUE_HOLDS_POINTER (value)' failed