Skip to content

Segfault / undefined behavior in Timeline::Close() #378

@musteresel

Description

@musteresel

I'm seeing segmentation faults when I close OpenShot. Today I took the time to look at the stacktrace, and look, libopenshot is to blame:

terminate called without an active exception                                                                                                                              
Caught signal 6 (SIGABRT)                                                                                                                                                 
---- Unhandled Exception: Stack Trace ---- 
  /nix/store/g88xj01xv7xzdx9dy2zwga0vk56fpfbm-glibc-2.27/lib/libc.so.6 ( abort                                     + 0x141 )  [0x7f5fdac88dc1]                            
  /nix/store/q2vnbr654204znx19ivblr2vhf134mac-gcc-7.4.0-lib/lib/libstdc++.so.6 ( __gnu_cxx::__verbose_terminate_handler()  + 0x125 )  [0x7f5fd24e5f75]                    
  /nix/store/q2vnbr654204znx19ivblr2vhf134mac-gcc-7.4.0-lib/lib/libstdc++.so.6 (                                           + 0x97d66)  [0x7f5fd24e3d66]                   
  /nix/store/q2vnbr654204znx19ivblr2vhf134mac-gcc-7.4.0-lib/lib/libstdc++.so.6 (                                           + 0x97db1)  [0x7f5fd24e3db1]                   
  /nix/store/q2vnbr654204znx19ivblr2vhf134mac-gcc-7.4.0-lib/lib/libstdc++.so.6 (                                           + 0x98aef)  [0x7f5fd24e4aef]                   
  /nix/store/b94fyqq44wzyw9yhsibzazkn2mhbpl1v-libopenshot-dev/lib/libopenshot.so.17 ( openshot::Timeline::Close()               + 0x265 )  [0x7f5fc72a48a5]               
  /nix/store/b94fyqq44wzyw9yhsibzazkn2mhbpl1v-libopenshot-dev/lib/libopenshot.so.17 ( openshot::Timeline::~Timeline()           + 0x315 )  [0x7f5fc72a4cb5]               
  /nix/store/b94fyqq44wzyw9yhsibzazkn2mhbpl1v-libopenshot-dev/lib/libopenshot.so.17 ( openshot::Timeline::~Timeline()           + 0x9   )  [0x7f5fc72a4cc9]               
  /nix/store/b94fyqq44wzyw9yhsibzazkn2mhbpl1v-libopenshot-dev/lib/python3.7/site-packages/_openshot.so (                                           + 0x82a38)  [0x7f5fc7  39ba38]                                                                                                                                                                   
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 ( _PyMethodDef_RawFastCallDict              + 0x339 )  [0x7f5fdb32cdd9]              
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 ( _PyCFunction_FastCallDict                 + 0x25  )  [0x7f5fdb32ce65]              
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0xa0592)  [0x7f5fdb32d592]             
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 ( PyObject_CallFunctionObjArgs              + 0x99  )  [0x7f5fdb32d999]              
  /nix/store/b94fyqq44wzyw9yhsibzazkn2mhbpl1v-libopenshot-dev/lib/python3.7/site-packages/_openshot.so (                                           + 0x5b5d2)  [0x7f5fc7  3745d2]                                                                                                                                                                   
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0xddc45)  [0x7f5fdb36ac45]             
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0x10676d)  [0x7f5fdb39376d]            
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0xddc45)  [0x7f5fdb36ac45]             
  /nix/store/nb3v6jhh60zcn2xcgsyhkm026vvpdq5h-python3.7-PyQt5.sip-4.19.18/lib/python3.7/site-packages/PyQt5/sip.so (                                           + 0x5cc3)    [0x7f5fd02e8cc3]                                                                                                                                                        
  /nix/store/nb3v6jhh60zcn2xcgsyhkm026vvpdq5h-python3.7-PyQt5.sip-4.19.18/lib/python3.7/site-packages/PyQt5/sip.so (                                           + 0x8e64)    [0x7f5fd02ebe64]                                                                                                                                                        
  /nix/store/nb3v6jhh60zcn2xcgsyhkm026vvpdq5h-python3.7-PyQt5.sip-4.19.18/lib/python3.7/site-packages/PyQt5/sip.so (                                           + 0x15571  )  [0x7f5fd02f8571]                                                                                                                                                       
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0x1067b0)  [0x7f5fdb3937b0]            
  /nix/store/xw06hkwpxyjxil3d5h374imxp3qhkscq-python3-3.7.4/lib/libpython3.7m.so.1.0 (                                           + 0xddc45)  [0x7f5fdb36ac45]             
  /nix/store/nb3v6jhh60zcn2xcgsyhkm026vvpdq5h-python3.7-PyQt5.sip-4.19.18/lib/python3.7/site-packages/PyQt5/sip.so (                                           + 0x5cc3)    [0x7f5fd02e8cc3]                                                                                                                                                        
  /nix/store/nb3v6jhh60zcn2xcgsyhkm026vvpdq5h-python3.7-PyQt5.sip-4.19.18/lib/python3.7/site-packages/PyQt5/sip.so (                                           + 0x8e64)    [0x7f5fd02ebe64]                                                                                                              
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Network.so.5 (                                           + 0x14b59d)  [0x7f5fcde5b59d]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QObject::event(QEvent*)                   + 0xe2  )  [0x7f5fd28a1b02]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QCoreApplication::notifyInternal2(QObject*, QEvent*)  + 0x101 )  [0x7f5fd28711a1]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*)  + 0x1a7 )  [0x7f5fd2873d77]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 (                                           + 0x2f8e23)  [0x7f5fd28cee23]
  /nix/store/9gvnlkyjabbhl26ijy4apv62dga430y5-glib-2.60.6/lib/libglib-2.0.so.0 ( g_main_context_dispatch                   + 0x2e7 )  [0x7f5fd03cc8e7]
  /nix/store/9gvnlkyjabbhl26ijy4apv62dga430y5-glib-2.60.6/lib/libglib-2.0.so.0 (                                           + 0x51b20)  [0x7f5fd03ccb20]
  /nix/store/9gvnlkyjabbhl26ijy4apv62dga430y5-glib-2.60.6/lib/libglib-2.0.so.0 ( g_main_context_iteration                  + 0x2c  )  [0x7f5fd03ccbac]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)  + 0x5f  )  [0x7f5fd28ce43f]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)  + 0x13a )  [0x7f5fd286f4da]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 ( QThread::exec()                           + 0x6a  )  [0x7f5fd268896a]
  /nix/store/lf18ivvikaprv6alcm2gcvsqljg1qfsg-qtbase-5.12.3/lib/libQt5Core.so.5 (                                           + 0xb4112)  [0x7f5fd268a112]
  /nix/store/g88xj01xv7xzdx9dy2zwga0vk56fpfbm-glibc-2.27/lib/libpthread.so.0 (                                           + 0x7ef7)  [0x7f5fdb273ef7]
  /nix/store/g88xj01xv7xzdx9dy2zwga0vk56fpfbm-glibc-2.27/lib/libc.so.6 ( clone                                     + 0x3f  )  [0x7f5fdad4522f]
---- End of Stack Trace ----

The culprit is - I think - quickly found in Timeline::Close():

	for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr)
	{
		// Get clip object from the iterator
		Clip *clip = (*clip_itr);

		// Open or Close this clip, based on if it's intersecting or not
		update_open_clips(clip, false);
	}

What does update_open_clips()? I've removed uninteresting comments / logging but added what's happening in this case:

void Timeline::update_open_clips(Clip *clip, bool does_clip_intersect /* FALSE for us */)
{
	bool clip_found = open_clips.count(clip); // DEFINITIVELY TRUE for us!

	if (clip_found && !does_clip_intersect) // Yep, TRUE
	{
		open_clips.erase(clip); // Ouch, erase in loop!

erase invalides the iterator (clip_itr) ... thus incrementing it is undefined behavior!

I'm fixing this as soon as I have time for it, opening this issue so that I don't forget it / it doesn't get lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleThis issue has not had any activity in 90 days :(

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions