RESOLVED FIXED 280150
[GTK] Crash on inputting booking field on IRCTC website in ScriptMessageClientGtk::didPostMessage
https://bugs.webkit.org/show_bug.cgi?id=280150
Summary [GTK] Crash on inputting booking field on IRCTC website in ScriptMessageClien...
Akarshan Biswas
Reported 2024-09-22 07:02:09 PDT
Created attachment 472629 [details] The text file containing back trace from the core dump after webkitgtk crashed Experienced a weird crash while inputting fields during booking in irctc.co.in website. Attaching back trace with this. Unfortunately, reproducing this is difficult since it needs to be a valid login for filing up the reservation form for booking trains on that website and that too does not crash when I tried testing it later. Maybe, the bt attached might shred some light. Filing this issue nevertheless for improvement. Also, Michael says: "the ScriptMessageClientGtk does not own its WebKitUserContentManager and just assumes it will never outlive the WebKitUserContentManager. Presumably that assumption is wrong."
Attachments
The text file containing back trace from the core dump after webkitgtk crashed (27.95 KB, text/plain)
2024-09-22 07:02 PDT, Akarshan Biswas
no flags
Michael Catanzaro
Comment 1 2024-09-23 14:01:31 PDT Comment hidden (obsolete)
Michael Catanzaro
Comment 2 2024-09-24 18:53:29 PDT
I just hit this crash on an internal Red Hat website, but wasn't able to reproduce it unfortunately. It would be easier to debug if it was reproducible. Anyway, my stack trace looks identical to the one you attached. Notably: (gdb) frame 4 #4 0x00007f18c360d0a1 in ScriptMessageClientGtk::didPostMessage (this=0x7f18aa771840, serializedScriptValue=...) at /buildstream/gnome/sdk/webkitgtk-6.0.bst/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp:411 warning: 411 /buildstream/gnome/sdk/webkitgtk-6.0.bst/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp: No such file or directory (gdb) print m_manager $1 = 0x55c993bc4a10 (gdb) print ((GObject*)m_manager)->ref_count $2 = 2863311530 2863311530 is notably 0b10101010101010101010101010101010, so clearly the WebKitUserContentManager is not valid. Should have used a smart pointer....
Akarshan Biswas
Comment 3 2024-09-24 20:11:58 PDT
If my understanding is correct, it is indeed declared as a raw pointer here: https://github.com/WebKit/WebKit/blob/8bac10aa5b34def64db6d3d3cdabd4f75482b42c/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp#L437 Maybe using a smart pointer like [GRefPtr](https://trac.webkit.org/wiki/GRefPtr) will ensure its proper memory management? I am sure if g_signal_emit() expects a raw pointer, we can pass it as m_manager.get() How that raw pointer will handle after being passed to the g_signal_emit(), I have no idea tbh, so I won't comment further.
Michael Catanzaro
Comment 4 2024-09-25 07:19:49 PDT
Right, it either needs to be GRefPtr, or GWeakPtr if that would lead to a reference cycle (which I need to verify). But ideally we would also understand why this is happening in the first place. (In reply to Akarshan Biswas from comment #3) > How that raw pointer will handle after being passed to the g_signal_emit(), > I have no idea tbh, so I won't comment further. Doesn't matter, since there's no need to hold ownership there.
Michael Catanzaro
Comment 5 2024-09-27 11:49:09 PDT Comment hidden (obsolete)
Michael Catanzaro
Comment 6 2024-09-27 13:01:51 PDT
I found a reproducer. The bug occurs when unfocusing a form element in a tab in a related web view (a tab opened by another tab, controlled by the original tab) after the opener web view was closed. But sadly only on this one particular internal Red Hat website. :( Problem is clear enough though: register five script message handlers, then unregister four of them, then destroy the WebKitUserContentManager and also the ScriptMessageClientGtk (so using a smart pointer wouldn't help here), leaving one message handler remaining....
Michael Catanzaro
Comment 7 2024-09-27 13:19:50 PDT
(In reply to Michael Catanzaro from comment #6) > then destroy the WebKitUserContentManager and also > the ScriptMessageClientGtk (so using a smart pointer wouldn't help here), > leaving one message handler remaining.... Sorry, the ScriptMessageClientGtk only gets destroyed when the message handler is unregistered, so a smart pointer would definitely help. Let's do that.
Michael Catanzaro
Comment 8 2024-09-27 14:23:18 PDT
Michael Catanzaro
Comment 9 2024-09-27 14:47:21 PDT
EWS
Comment 10 2024-10-30 14:11:23 PDT
Committed 285924@main (55790984429f): <https://commits.webkit.org/285924@main> Reviewed commits have been landed. Closing PR #34386 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.