bugGNU Octave - Bugs: bug #64220, Octave crashes while saving class...

 
 

bug #64220: Octave crashes while saving class object to file

Submitter:  Vipul Cariappa <vipul_cariappa>
Submitted:  Fri 19 May 2023 12:34:40 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  8.3.0 Planned Release:  8.3.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 22 May 2023 11:35:30 PM UTC, comment #5: 

Works for me on both 8.2.1 and 9.0.0

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 22 May 2023 11:25:57 PM UTC, comment #4: 

Incidentally, there is no need for a loadobj.m file if you are not making any changes to the loaded data.

Rik <rik5>
Group administrator
Mon 22 May 2023 11:25:29 PM UTC, comment #3: 

I checked in a fix on the stable branch of Octave here: http://hg.savannah.gnu.org/hgweb/octave/rev/6cd803819bd2.

I pulled the change across to the dev branch so if you update to the latest dev tip you will be able to test this.

Marking as Ready for Test.

Rik <rik5>
Group administrator
Mon 22 May 2023 03:57:28 PM UTC, comment #2: 

Interestingly, I have tested this code against historical versions of Octave including 7.3, 6.4, and 5.2 and they all produce a segfault.

Apparently this bug has been present for years, but simply not evident because very few people use the old style @class code structure anymore (preferring classdef instead).

Rik <rik5>
Group administrator
Mon 22 May 2023 03:28:22 AM UTC, comment #1: 

Confirmed on the dev branch, and also with Octave 8.2 (last stable release).

Rik <rik5>
Group administrator
Fri 19 May 2023 12:34:40 PM UTC, original submission:  

See discussion at
https://octave.discourse.group/t/octave-crashes-while-saving-data-to-file/4503

I am using an old-style class, and want to save the contents of the class into a file. But before the contents are stored I want to initiate a field metadata with some value. Saving the class instance after initiating the metadata field in saveobj function causes a segmentation fault.

Code (also attached):


% @myobject/myobject.m
function obj = myobject (data)
    obj.data = data;
    obj = class (obj, "myobject");
endfunction



% @myobject/loadobj.m
function lobj = loadobj (self)
    lobj = self;
endfunction



% @myobject/saveobj.m
function sobj = saveobj (self)
    sobj = self;
    sobj.metadata = 0; # Add extra meta data
endfunction


Crash with backtrace:

octave:3> x = myobject ("Vipul")
x =

  <class myobject>

octave:4> save savefile

Thread 7 "QThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffed6734640 (LWP 818823)]
0x00007ffff1cb9641 in __memmove_avx_unaligned () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install GraphicsMagick-1.3.40-1.el9.x86_64 GraphicsMagick-c++-1.3.40-1.el9.x86_64 adwaita-qt5-1.4.2-1.el9.x86_64 arpack-3.8.0-6.el9.x86_64 flexiblas-netlib-3.3.1-2.el9.x86_64 flexiblas-openblas-openmp-3.3.1-2.el9.x86_64 fontconfig-2.14.0-2.el9.x86_64 freetype-2.13.0-2.el9.x86_64 gl2ps-1.4.2-5.el9.x86_64 glibc-2.34-67.el9.x86_64 hdf5-1.12.1-7.el9.1.x86_64 krb5-libs-1.20.1-8.el9.x86_64 libadwaita-qt5-1.4.2-1.el9.x86_64 libaec-1.0.6-1.el9.x86_64 libblkid-2.37.4-11.el9.x86_64 libcurl-7.87.0-4.el9.x86_64 libffi-3.4.2-8.el9.x86_64 libgcrypt-1.10.0-10.el9.x86_64 libjpeg-turbo-2.0.90-6.el9.x86_64 libmount-2.37.4-11.el9.x86_64 libselinux-3.5-1.el9.x86_64 libssh-0.10.4-8.el9.x86_64 libuuid-2.37.4-11.el9.x86_64 openblas-openmp-0.3.21-4.el9.x86_64 openssl-libs-3.0.8-1.el9.x86_64 qgnomeplatform-0.9.0-1.el9.x86_64 qrupdate-1.1.2-26.el9.x86_64 qscintilla-qt5-2.13.4-1.el9.x86_64 qt5-qtbase-5.15.9-3.el9.x86_64 qt5-qtbase-gui-5.15.9-3.el9.x86_64 qt5-qttools-libs-help-5.15.9-3.el9.x86_64 qt5-qtx11extras-5.15.9-1.el9.x86_64 systemd-libs-252-8.el9.x86_64 zlib-1.2.11-40.el9.x86_64
(gdb) thread apply all bt

Thread 8 (Thread 0x7ffed5bff640 (LWP 818824) "QThread"):
#0  0x00007ffff1c55b0a in sigtimedwait () at /lib64/libc.so.6
#1  0x00007ffff1c5514c in sigwait () at /lib64/libc.so.6
#2  0x00007ffff43befea in signal_watcher(void*) (arg=0x7ffff75314a5 <octave::generic_sig_handler(int)>) at ../liboctave/wrappers/cxx-signal-helpers.cc:179
#3  0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#4  0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 7 (Thread 0x7ffed6734640 (LWP 818823) "QThread"):
#0  0x00007ffff1cb9641 in __memmove_avx_unaligned () at /lib64/libc.so.6
#1  0x00007ffff7b2f4b9 in std::__copy_move<false, true, std::random_access_iterator_tag>::__copy_m<long>(long const*, long const*, long*) (__first=0x1, __last=0x1a9, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algobase.h:431
#2  0x00007ffff7b2f2e1 in std::__copy_move_a2<false, long*, long*>(long*, long*, long*) (__first=0x1, __last=0x1a9, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algobase.h:495
#3  0x00007ffff7b2ef6b in std::__copy_move_a1<false, long*, long*>(long*, long*, long*) (__first=0x1, __last=0x1a9, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algobase.h:522
#4  0x00007ffff7b2ec88 in std::__copy_move_a<false, long*, long*>(long*, long*, long*) (__first=0x1, __last=0x1a9, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algobase.h:529
--Type <RET> for more, q to quit, c to continue without paging--c
#5  0x00007ffff7b2e94c in std::copy<long*, long*>(long*, long*, long*) (__first=0x1, __last=0x1a9, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algobase.h:620
#6  0x00007ffff7b2e5bc in std::__copy_n<long*, long, long*>(long*, long, long*, std::random_access_iterator_tag) (__first=0x1, __n=53, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algo.h:725
#7  0x00007ffff7b2e018 in std::copy_n<long*, long, long*>(long*, long, long*) (__first=0x1, __n=53, __result=0x7ffec835a550) at /usr/include/c++/11/bits/stl_algo.h:757
#8  0x00007ffff6ae71b6 in dim_vector::dim_vector(dim_vector const&) (this=0x7ffec844db40, dv=...) at ../liboctave/array/dim-vector.h:193
#9  0x00007ffff6afad5d in Array<octave_value, std::allocator<octave_value> >::Array(Array<octave_value, std::allocator<octave_value> > const&) (this=0x7ffec844db38, a=...) at ../liboctave/array/Array.h:334
#10 0x00007ffff6e5d19b in Cell::Cell(Cell const&) (this=0x7ffec844db38, c=...) at ../libinterp/corefcn/Cell.h:48
#11 0x00007ffff6e5d3b8 in octave_base_matrix<Cell>::octave_base_matrix(Cell const&, MatrixType const&) (this=0x7ffec844db20, m=..., t=...) at ../libinterp/octave-value/ov-base-mat.h:60
#12 0x00007ffff6f31553 in octave_cell::octave_cell(Cell const&) (this=0x7ffec844db20, c=...) at ../libinterp/octave-value/ov-cell.h:58
#13 0x00007ffff6f1b04a in octave_value::octave_value(Cell const&, bool) (this=0x7ffed6731318, c=..., is_csl=false) at ../libinterp/octave-value/ov.cc:534
#14 0x00007ffff6e70c64 in octave_class::save_ascii(std::ostream&) (this=0x7ffec8577a70, os=...) at ../libinterp/octave-value/ov-class.cc:1201
#15 0x00007ffff6eb12aa in octave_value::save_ascii(std::ostream&) (this=0x7ffed6731578, os=...) at ../libinterp/octave-value/ov.h:1340
#16 0x00007ffff743914d in save_text_data(std::ostream&, octave_value const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int) (os=..., val_arg=..., name="x", mark_global=false, precision=17) at ../libinterp/corefcn/ls-oct-text.cc:381
#17 0x00007ffff740cf12 in octave::load_save_system::do_save(std::ostream&, octave_value const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, octave::load_save_format const&, bool) (this=0x7ffec8009890, os=..., tc=..., name="x", help="", global=false, fmt=..., save_as_floats=false) at ../libinterp/corefcn/load-save.cc:940
#18 0x00007ffff740d119 in octave::load_save_system::do_save(std::ostream&, octave::symbol_info const&, octave::load_save_format const&, bool) (this=0x7ffec8009890, os=..., syminfo=..., fmt=..., save_as_floats=false) at ../libinterp/corefcn/load-save.cc:993
#19 0x00007ffff740ce3f in octave::load_save_system::save_vars(std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, octave::load_save_format const&, bool) (this=0x7ffec8009890, os=..., pattern="*", fmt=..., save_as_floats=false) at ../libinterp/corefcn/load-save.cc:923
#20 0x00007ffff740c00f in octave::load_save_system::save_vars(string_vector const&, int, int, std::ostream&, octave::load_save_format const&, bool, bool) (this=0x7ffec8009890, argv=..., argv_idx=1, argc=1, os=..., fmt=..., save_as_floats=false, write_header_info=true) at ../libinterp/corefcn/load-save.cc:684
#21 0x00007ffff740f9c0 in octave::load_save_system::save(octave_value_list const&, int) (this=0x7ffec8009890, args=..., nargout=0) at ../libinterp/corefcn/load-save.cc:1545
#22 0x00007ffff740fd06 in octave::Fsave(octave::interpreter&, octave_value_list const&, int) (interp=..., args=..., nargout=0) at ../libinterp/corefcn/load-save.cc:1835
#23 0x00007ffff6ffc439 in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) (this=0x7ffec8008c38, builtin_function=..., nargout=0, args=...) at ../libinterp/parse-tree/pt-eval.cc:3367
#24 0x00007ffff6e54927 in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) (this=0x7ffec80edd70, tw=..., nargout=0, args=...) at ../libinterp/octave-value/ov-builtin.cc:49
#25 0x00007ffff6eb8140 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) (this=0x7ffec80edd70, tw=..., nargout=0, args=...) at ../libinterp/octave-value/ov-fcn.cc:57
#26 0x00007ffff701e05d in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) (this=0x7ffec822df80, tw=..., nargout=0) at ../libinterp/parse-tree/pt-idx.cc:427
#27 0x00007ffff7020b97 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) (this=0x7ffec822df80, tw=..., nargout=0) at ../libinterp/parse-tree/pt-idx.h:104
#28 0x00007ffff6ffdf45 in octave::tree_evaluator::visit_statement(octave::tree_statement&) (this=0x7ffec8008c38, stmt=...) at ../libinterp/parse-tree/pt-eval.cc:3863
#29 0x00007ffff702a942 in octave::tree_statement::accept(octave::tree_walker&) (this=0x7ffec848b340, tw=...) at ../libinterp/parse-tree/pt-stmt.h:120
#30 0x00007ffff6ffe41f in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) (this=0x7ffec8008c38, lst=...) at ../libinterp/parse-tree/pt-eval.cc:3948
#31 0x00007ffff6e0450c in octave::tree_statement_list::accept(octave::tree_walker&) (this=0x7ffec84de050, tw=...) at ../libinterp/parse-tree/pt-stmt.h:193
#32 0x00007ffff6ff358c in octave::tree_evaluator::eval(std::shared_ptr<octave::tree_statement_list>&, bool) (this=0x7ffec8008c38, stmt_list=std::shared_ptr<octave::tree_statement_list> (use count 2, weak count 0) = {...}, interactive=true) at ../libinterp/parse-tree/pt-eval.cc:985
#33 0x00007ffff6ff2c06 in octave::tree_evaluator::repl() (this=0x7ffec8008c38) at ../libinterp/parse-tree/pt-eval.cc:804
#34 0x00007ffff73cb4c5 in octave::interpreter::main_loop() (this=0x7ffec8008a40) at ../libinterp/corefcn/interpreter.cc:1315
#35 0x00007ffff73c5f1a in octave::interpreter::execute() (this=0x7ffec8008a40) at ../libinterp/corefcn/interpreter.cc:883
#36 0x00007ffff7bef4b0 in octave::interpreter_qobject::execute() (this=0x724bc0) at ../libgui/src/interpreter-qobject.cc:87
#37 0x00007ffff7cfcdb2 in octave::interpreter_qobject::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (_o=0x724bc0, _c=QMetaObject::InvokeMetaMethod, _id=2, _a=0x4b15e8) at libgui/src/moc-interpreter-qobject.cc:88
#38 0x00007ffff4ed2cd9 in QObject::event(QEvent*) () at /lib64/libQt5Core.so.5
#39 0x00007ffff5baf533 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib64/libQt5Widgets.so.5
#40 0x00007ffff7c6152d in octave::octave_qapplication::notify(QObject*, QEvent*) (this=0x4a7110, receiver=0x724bc0, ev=0x4b15a0) at ../libgui/src/octave-qobject.cc:148
#41 0x00007ffff4ea7938 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib64/libQt5Core.so.5
#42 0x00007ffff4eaae86 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /lib64/libQt5Core.so.5
#43 0x00007ffff4ef9d07 in postEventSourceDispatch(_GSource*, int (*)(void*), void*) () at /lib64/libQt5Core.so.5
#44 0x00007ffff0f2fe2f in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
#45 0x00007ffff0f84508 in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#46 0x00007ffff0f2d5f3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#47 0x00007ffff4ef97a8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#48 0x00007ffff4ea6342 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#49 0x00007ffff4ce89aa in QThread::exec() () at /lib64/libQt5Core.so.5
#50 0x00007ffff4ce9c8d in QThreadPrivate::start(void*) () at /lib64/libQt5Core.so.5
#51 0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#52 0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 5 (Thread 0x7ffed7011640 (LWP 818817) "gdbus"):
#0  0x00007ffff1d4296f in poll () at /lib64/libc.so.6
#1  0x00007ffff0f8449c in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#2  0x00007ffff0f2f483 in g_main_loop_run () at /lib64/libglib-2.0.so.0
#3  0x00007ffedc1eae1a in gdbus_shared_thread_func.lto_priv () at /lib64/libgio-2.0.so.0
#4  0x00007ffff0f5e582 in g_thread_proxy () at /lib64/libglib-2.0.so.0
#5  0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#6  0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 4 (Thread 0x7ffed7812640 (LWP 818816) "gmain"):
#0  0x00007ffff1d4296f in poll () at /lib64/libc.so.6
#1  0x00007ffff0f8449c in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#2  0x00007ffff0f2d5f3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#3  0x00007ffff0f2d641 in glib_worker_main () at /lib64/libglib-2.0.so.0
#4  0x00007ffff0f5e582 in g_thread_proxy () at /lib64/libglib-2.0.so.0
#5  0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#6  0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 3 (Thread 0x7ffedd515640 (LWP 818802) "QXcbEventQueue"):
#0  0x00007ffff1d4296f in poll () at /lib64/libc.so.6
#1  0x00007ffff1a75f42 in poll (__timeout=-1, __nfds=1, __fds=0x7ffedd514108) at /usr/include/bits/poll2.h:48
#2  _xcb_conn_wait (c=0x4bed80, vector=0x0, count=0x0, cond=<optimized out>) at /usr/src/debug/libxcb-1.13.1-9.el9.x86_64/src/xcb_conn.c:479
#3  0x00007ffff1a7790c in _xcb_conn_wait (count=0x0, vector=0x0, cond=0x4bedc0, c=0x4bed80) at /usr/src/debug/libxcb-1.13.1-9.el9.x86_64/src/xcb_conn.c:445
#4  xcb_wait_for_event (c=0x4bed80) at /usr/src/debug/libxcb-1.13.1-9.el9.x86_64/src/xcb_in.c:697
#5  0x00007fffee98f407 in QXcbEventQueue::run() () at /lib64/libQt5XcbQpa.so.5
#6  0x00007ffff4ce9c8d in QThreadPrivate::start(void*) () at /lib64/libQt5Core.so.5
#7  0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#8  0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 2 (Thread 0x7ffeddd16640 (LWP 818801) "QDBusConnection"):
#0  0x00007ffff1d4296f in poll () at /lib64/libc.so.6
#1  0x00007ffff0f8449c in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#2  0x00007ffff0f2d5f3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#3  0x00007ffff4ef97a8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#4  0x00007ffff4ea6342 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#5  0x00007ffff4ce89aa in QThread::exec() () at /lib64/libQt5Core.so.5
#6  0x00007ffeddd85b8b in QDBusConnectionManager::run() () at /lib64/libQt5DBus.so.5
#7  0x00007ffff4ce9c8d in QThreadPrivate::start(void*) () at /lib64/libQt5Core.so.5
#8  0x00007ffff1c9f832 in start_thread () at /lib64/libc.so.6
#9  0x00007ffff1c3f450 in clone3 () at /lib64/libc.so.6

Thread 1 (Thread 0x7ffff1a3a300 (LWP 818737) "octave-gui"):
#0  0x00007ffff1d4296f in poll () at /lib64/libc.so.6
#1  0x00007ffff0f8449c in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
#2  0x00007ffff0f2d5f3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#3  0x00007ffff4ef97a8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#4  0x00007ffff4ea6342 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
#5  0x00007ffff4eae874 in QCoreApplication::exec() () at /lib64/libQt5Core.so.5
#6  0x00007ffff7c62e6c in octave::base_qobject::exec() (this=0x7fffffffbfb0) at ../libgui/src/octave-qobject.cc:423
#7  0x00007ffff7c77563 in octave::qt_application::execute() (this=0x7fffffffc100) at ../libgui/src/qt-application.cc:102
#8  0x0000000000402767 in main(int, char**) (argc=8, argv=0x7fffffffc508) at ../src/main-gui.cc:150
(gdb)


The segfault occurres in linux machines.

In windows it gives the following error (tested with octave 8.2.0)

>> x = myobject ("Vipul")
x =

  <class myobject>

>> save savefile
error: out of memory or dimension too large for Octave's index type



Vipul Cariappa <vipul_cariappa>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #54765:  saveobj.m added by vipul_cariappa (105B - text/plain)
file #54766:  myobject.m added by vipul_cariappa (99B - text/plain)
file #54767:  loadobj.m added by vipul_cariappa (60B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by vipul_cariappa (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-05-23 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2023-05-22 rik5 StatusConfirmed Ready For Test
        Fixed ReleaseNone 8.3.0
    2023-05-22 rik5 StatusNone Confirmed
        Planned ReleaseNone 8.3.0
    2023-05-19 vipul_cariappa Attached File- Added saveobj.m, #54765
        Attached File- Added myobject.m, #54766
        Attached File- Added loadobj.m, #54767

    Back to the top

    Powered by Savane 3.13-ee12.
    Corresponding source code