bugGNU Octave - Bugs: bug #63682, mat2cell returns incorrect value...

 
 

bug #63682: mat2cell returns incorrect value when only one output dimensions is specified and input is N-D array

Submitter:  Mario Storti <mstorti>
Submitted:  Thu 19 Jan 2023 10:34:12 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Mario Storti Open/Closed:  * Closed
Release:  * 8.0.90 Operating System:  * Any
Fixed Release:  9.1.0 Planned Release:  9.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 20 Feb 2023 05:28:37 AM UTC, comment #19: 

Works for me as well:

octave:1> test libinterp/corefcn/cellfun.cc-tst
warning: inline is obsolete; use anonymous functions instead
PASSES 135 out of 135 tests
octave:2> version -hgid
ans = e27744dfb13a


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 20 Feb 2023 05:18:19 AM UTC, comment #18: 

I checked in a bigger change which appears to fix the problem (passes ASAN testing).  See http://hg.savannah.gnu.org/hgweb/octave/rev/e27744dfb13a.  The problem seems to have been that the for loop that assigned values to the output called increment_index() for every loop iteration.  This makes sense for each iteration except the last one.  On the last one, the indexing operation has taken place and all values have been calculated.  The loop body will not be executed again and so there is no need to increment the index.  And if you do increment the index then it overflows.  This bug has been hidden in Octave for a very long time.  I also added as many comments as I could because this was very confusing code.

Rik <rik5>
Group administrator
Sun 19 Feb 2023 05:46:41 PM UTC, comment #17: 

It still crashes with ASAN:


octave:1> version -hgid
ans = 79abf4cdcd95
octave:2> test libinterp/corefcn/cellfun.cc-tst
warning: inline is obsolete; use anonymous functions instead
=================================================================
==318865==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000dbf1a0 at pc 0x7f11412722da bp 0x7f111df217e0 sp 0x7f111df217d0
READ of size 8 at 0x602000dbf1a0 thread T7 (QThread)
    #0 0x7f11412722d9 in octave_value::operator=(octave_value&&) ../libinterp/octave-value/ov.h:403
    #1 0x7f1142308c9c in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2112
    #2 0x7f1142306aab in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2128
    #3 0x7f11422ceabc in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2298
    #4 0x7f11420f665c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #5 0x7f1141cda61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #6 0x7f1141dc2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #7 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #8 0x7f1142147c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #9 0x7f11420bfd04 in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #10 0x7f11420fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #11 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #12 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #13 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #14 0x7f11420f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #15 0x7f1141ec8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #16 0x7f1141ec83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #17 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #18 0x7f11420e1c2a in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #19 0x7f11420e27d9 in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #20 0x7f11429ce441 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #21 0x7f114207f32d in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #22 0x7f11420f677c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #23 0x7f1141cda61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #24 0x7f1141dc2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #25 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #26 0x7f1142147c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #27 0x7f11420fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #28 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #29 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #30 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #31 0x7f11420fbdd4 in octave::tree_evaluator::visit_try_catch_command(octave::tree_try_catch_command&) ../libinterp/parse-tree/pt-eval.cc:4063
    #32 0x7f1142138efe in octave::tree_try_catch_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:80
    #33 0x7f11420fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #34 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #35 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #36 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #37 0x7f11420f99b2 in octave::tree_evaluator::visit_if_command_list(octave::tree_if_command_list&) ../libinterp/parse-tree/pt-eval.cc:3711
    #38 0x7f114211114e in octave::tree_if_command_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:111
    #39 0x7f11420f95c9 in octave::tree_evaluator::visit_if_command(octave::tree_if_command&) ../libinterp/parse-tree/pt-eval.cc:3689
    #40 0x7f114215c10e in octave::tree_if_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:141
    #41 0x7f11420fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #42 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #43 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #44 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #45 0x7f11420fd436 in octave::tree_evaluator::visit_unwind_protect_command(octave::tree_unwind_protect_command&) ../libinterp/parse-tree/pt-eval.cc:4208
    #46 0x7f1142138f72 in octave::tree_unwind_protect_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:142
    #47 0x7f11420fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #48 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #49 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #50 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #51 0x7f1142114fbd in void octave::tree_evaluator::execute_range_loop<double>(octave::range<double, void> const&, int, octave::octave_lvalue&, octave::tree_statement_list*) ../libinterp/parse-tree/pt-eval.cc:3028
    #52 0x7f11420f3116 in octave::tree_evaluator::visit_simple_for_command(octave::tree_simple_for_command&) ../libinterp/parse-tree/pt-eval.cc:3075
    #53 0x7f114214f8a0 in octave::tree_simple_for_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-loop.h:179
    #54 0x7f11420fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #55 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #56 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #57 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #58 0x7f11420f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #59 0x7f1141ec8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #60 0x7f1141ec83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #61 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #62 0x7f1142147c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #63 0x7f11420fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #64 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #65 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #66 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #67 0x7f11420e15c3 in octave::tree_evaluator::eval(std::shared_ptr<octave::tree_statement_list>&, bool) ../libinterp/parse-tree/pt-eval.cc:985
    #68 0x7f11420e02b1 in octave::tree_evaluator::repl() ../libinterp/parse-tree/pt-eval.cc:804
    #69 0x7f11429cd0da in octave::interpreter::main_loop() ../libinterp/corefcn/interpreter.cc:1316
    #70 0x7f11429bfb74 in octave::interpreter::execute() ../libinterp/corefcn/interpreter.cc:882
    #71 0x7f1143d16f80 in octave::interpreter_qobject::execute() ../libgui/src/interpreter-qobject.cc:87
    #72 0x7f1143f9f834 in octave::interpreter_qobject::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) libgui/src/moc-interpreter-qobject.cc:88
    #73 0x7f113f6d1a98 in QObject::event(QEvent*) (/lib64/libQt5Core.so.5+0x2d1a98)
    #74 0x7f11403ae422 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/lib64/libQt5Widgets.so.5+0x1ae422)
    #75 0x7f1143e1f0be in octave::octave_qapplication::notify(QObject*, QEvent*) ../libgui/src/octave-qobject.cc:146
    #76 0x7f113f6a7357 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/lib64/libQt5Core.so.5+0x2a7357)
    #77 0x7f113f6aa8b5 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (/lib64/libQt5Core.so.5+0x2aa8b5)
    #78 0x7f113f6f8fa6 in postEventSourceDispatch(_GSource*, int (*)(void*), void*) (/lib64/libQt5Core.so.5+0x2f8fa6)
    #79 0x7f113b51ae2e in g_main_context_dispatch (/lib64/libglib-2.0.so.0+0x54e2e)
    #80 0x7f113b56f507 in g_main_context_iterate.constprop.0 (/lib64/libglib-2.0.so.0+0xa9507)
    #81 0x7f113b5185f2 in g_main_context_iteration (/lib64/libglib-2.0.so.0+0x525f2)
    #82 0x7f113f6f8a47 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2f8a47)
    #83 0x7f113f6a5d61 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2a5d61)
    #84 0x7f113f4e89c9 in QThread::exec() (/lib64/libQt5Core.so.5+0xe89c9)
    #85 0x7f113f4e9bf8 in QThreadPrivate::start(void*) (/lib64/libQt5Core.so.5+0xe9bf8)
    #86 0x7f113b69f801 in start_thread (/lib64/libc.so.6+0x9f801)
    #87 0x7f113b63f44f in __GI___clone3 (/lib64/libc.so.6+0x3f44f)

0x602000dbf1a0 is located 0 bytes to the right of 16-byte region [0x602000dbf190,0x602000dbf1a0)
allocated by thread T7 (QThread) here:
    #0 0x7f11448b6367 in operator new(unsigned long) (/lib64/libasan.so.6+0xb6367)
    #1 0x7f114123bc1b in __gnu_cxx::new_allocator<octave_value>::allocate(unsigned long, void const*) /usr/include/c++/11/ext/new_allocator.h:127
    #2 0x7f114123b2be in std::allocator_traits<std::allocator<octave_value> >::allocate(std::allocator<octave_value>&, unsigned long) /usr/include/c++/11/bits/alloc_traits.h:464
    #3 0x7f1141aaf4c0 in Array<octave_value, std::allocator<octave_value> >::ArrayRep::allocate(unsigned long) ../liboctave/array/Array.h:198
    #4 0x7f1141aaf063 in Array<octave_value, std::allocator<octave_value> >::ArrayRep::ArrayRep(long) ../liboctave/array/Array.h:167
    #5 0x7f1141a9fe43 in Array<octave_value, std::allocator<octave_value> >::clear(dim_vector const&) (/home/dima/src/dev/octave/gcc_asan/libinterp/.libs/liboctinterp.so.11+0xe9fe43)
    #6 0x7f1142308639 in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2079
    #7 0x7f1142306aab in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2128
    #8 0x7f11422ceabc in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2298
    #9 0x7f11420f665c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #10 0x7f1141cda61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #11 0x7f1141dc2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #12 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #13 0x7f1142147c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #14 0x7f11420bfd04 in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #15 0x7f11420fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #16 0x7f114215f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #17 0x7f11420fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #18 0x7f1141c1a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #19 0x7f11420f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #20 0x7f1141ec8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #21 0x7f1141ec83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #22 0x7f114214269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #23 0x7f11420e1c2a in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #24 0x7f11420e27d9 in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #25 0x7f11429ce441 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #26 0x7f114207f32d in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #27 0x7f11420f677c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #28 0x7f1141cda61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #29 0x7f1141dc2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57

Thread T7 (QThread) created by T0 here:
    #0 0x7f11448587d5 in pthread_create (/lib64/libasan.so.6+0x587d5)
    #1 0x7f113f4e969e in QThread::start(QThread::Priority) (/lib64/libQt5Core.so.5+0xe969e)

SUMMARY: AddressSanitizer: heap-buffer-overflow ../libinterp/octave-value/ov.h:403 in octave_value::operator=(octave_value&&)
Shadow bytes around the buggy address:
  0x0c04801afde0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c04801afdf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c04801afe00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c04801afe10: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa fd fd
  0x0c04801afe20: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
=>0x0c04801afe30: fa fa 00 00[fa]fa fd fd fa fa 00 00 fa fa fd fd
  0x0c04801afe40: fa fa 00 fa fa fa fd fd fa fa fd fd fa fa fd fa
  0x0c04801afe50: fa fa fd fd fa fa fd fd fa fa fd fd fa fa 00 00
  0x0c04801afe60: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fd
  0x0c04801afe70: fa fa fd fd fa fa fd fd fa fa 00 fa fa fa 00 00
  0x0c04801afe80: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==318865==ABORTING


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 19 Feb 2023 05:20:20 PM UTC, comment #16: 

This code was written a long time ago, and unfortunately who ever wrote it didn't comment it.  Despite being short, it is very dense and difficult to understand.  I thought I understood enough to make the first change, but I was wrong.  I will take one more look, but otherwise I think we revert everything and use Markus's change.

Rik <rik5>
Group administrator
Sun 19 Feb 2023 04:39:19 PM UTC, comment #15: 

`test cell2mat` is failing now:

octave:1> test cell2mat
***** test
 m = int8 (256*rand (4, 5, 6, 7, 8));
 c = mat2cell (m, [1 2 1], [1 2 2], [3 1 1 1], [4 1 2], [3 1 4]);
 assert (cell2mat (c), m);
!!!!! test failed
cell2mat: wrong type elements or mixed cells, structs, and matrices


I give up.

Since it is no longer crashing for me, I won't revert the changes like I initially planned. But I hope someone else who understands that part of the code better will be able to fix this properly. I already had my attempt with hg id 8c57434587c...

Markus Mützel <mmuetzel>
Group administrator
Sun 19 Feb 2023 04:21:52 PM UTC, comment #14: 

Next attempt here:
https://hg.savannah.gnu.org/hgweb/octave/rev/79abf4cdcd95

Let's see if this is working now...

Tbh, I found the previous approach (hg id 8c57434587c) a bit easier to follow. But I guess that comes to personal preference...

Markus Mützel <mmuetzel>
Group administrator
Sun 19 Feb 2023 01:26:45 PM UTC, comment #13: 

Yeah. I believe I'm seeing what is failing now.
That's a lesson for me to not mess with code for which I don't understand what it's doing.

I'll try another attempt after some local tests. If that won't work, I'll just revert to where we were before the last change and leave it for someone else to fix...

Markus Mützel <mmuetzel>
Group administrator
Sun 19 Feb 2023 01:06:56 PM UTC, comment #12: 

Also all Debian buildbots crashed there as well. For some reason all Fedora buildbots are fine.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 19 Feb 2023 01:01:47 PM UTC, comment #11: 

Still crashes for me:


octave:1> version -hgid
ans = 0e046fefbffa
octave:2> test libinterp/corefcn/cellfun.cc-tst
warning: inline is obsolete; use anonymous functions instead
=================================================================
==300334==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000dbc420 at pc 0x7fc5b3b08a73 bp 0x7fc58f64b810 sp 0x7fc58f64b800
READ of size 8 at 0x602000dbc420 thread T7 (QThread)
    #0 0x7fc5b3b08a72 in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2088
    #1 0x7fc5b3b06aab in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2106
    #2 0x7fc5b3aceabc in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2276
    #3 0x7fc5b38f665c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #4 0x7fc5b34da61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #5 0x7fc5b35c2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #6 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #7 0x7fc5b3947c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #8 0x7fc5b38bfd04 in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #9 0x7fc5b38fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #10 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #11 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #12 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #13 0x7fc5b38f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #14 0x7fc5b36c8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #15 0x7fc5b36c83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #16 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #17 0x7fc5b38e1c2a in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #18 0x7fc5b38e27d9 in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #19 0x7fc5b41cd611 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #20 0x7fc5b387f32d in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #21 0x7fc5b38f677c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #22 0x7fc5b34da61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #23 0x7fc5b35c2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #24 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #25 0x7fc5b3947c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #26 0x7fc5b38fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #27 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #28 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #29 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #30 0x7fc5b38fbdd4 in octave::tree_evaluator::visit_try_catch_command(octave::tree_try_catch_command&) ../libinterp/parse-tree/pt-eval.cc:4063
    #31 0x7fc5b3938efe in octave::tree_try_catch_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:80
    #32 0x7fc5b38fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #33 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #34 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #35 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #36 0x7fc5b38f99b2 in octave::tree_evaluator::visit_if_command_list(octave::tree_if_command_list&) ../libinterp/parse-tree/pt-eval.cc:3711
    #37 0x7fc5b391114e in octave::tree_if_command_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:111
    #38 0x7fc5b38f95c9 in octave::tree_evaluator::visit_if_command(octave::tree_if_command&) ../libinterp/parse-tree/pt-eval.cc:3689
    #39 0x7fc5b395c10e in octave::tree_if_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:141
    #40 0x7fc5b38fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #41 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #42 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #43 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #44 0x7fc5b38fd436 in octave::tree_evaluator::visit_unwind_protect_command(octave::tree_unwind_protect_command&) ../libinterp/parse-tree/pt-eval.cc:4208
    #45 0x7fc5b3938f72 in octave::tree_unwind_protect_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:142
    #46 0x7fc5b38fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #47 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #48 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #49 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #50 0x7fc5b3914fbd in void octave::tree_evaluator::execute_range_loop<double>(octave::range<double, void> const&, int, octave::octave_lvalue&, octave::tree_statement_list*) ../libinterp/parse-tree/pt-eval.cc:3028
    #51 0x7fc5b38f3116 in octave::tree_evaluator::visit_simple_for_command(octave::tree_simple_for_command&) ../libinterp/parse-tree/pt-eval.cc:3075
    #52 0x7fc5b394f8a0 in octave::tree_simple_for_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-loop.h:179
    #53 0x7fc5b38fa465 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #54 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #55 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #56 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #57 0x7fc5b38f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #58 0x7fc5b36c8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #59 0x7fc5b36c83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #60 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #61 0x7fc5b3947c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #62 0x7fc5b38fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #63 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #64 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #65 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #66 0x7fc5b38e15c3 in octave::tree_evaluator::eval(std::shared_ptr<octave::tree_statement_list>&, bool) ../libinterp/parse-tree/pt-eval.cc:985
    #67 0x7fc5b38e02b1 in octave::tree_evaluator::repl() ../libinterp/parse-tree/pt-eval.cc:804
    #68 0x7fc5b41cc2aa in octave::interpreter::main_loop() ../libinterp/corefcn/interpreter.cc:1316
    #69 0x7fc5b41bed44 in octave::interpreter::execute() ../libinterp/corefcn/interpreter.cc:882
    #70 0x7fc5b5516f80 in octave::interpreter_qobject::execute() ../libgui/src/interpreter-qobject.cc:87
    #71 0x7fc5b579f834 in octave::interpreter_qobject::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) libgui/src/moc-interpreter-qobject.cc:88
    #72 0x7fc5b0ed1a98 in QObject::event(QEvent*) (/lib64/libQt5Core.so.5+0x2d1a98)
    #73 0x7fc5b1bae422 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/lib64/libQt5Widgets.so.5+0x1ae422)
    #74 0x7fc5b561f0be in octave::octave_qapplication::notify(QObject*, QEvent*) ../libgui/src/octave-qobject.cc:146
    #75 0x7fc5b0ea7357 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/lib64/libQt5Core.so.5+0x2a7357)
    #76 0x7fc5b0eaa8b5 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (/lib64/libQt5Core.so.5+0x2aa8b5)
    #77 0x7fc5b0ef8fa6 in postEventSourceDispatch(_GSource*, int (*)(void*), void*) (/lib64/libQt5Core.so.5+0x2f8fa6)
    #78 0x7fc5acd1ae2e in g_main_context_dispatch (/lib64/libglib-2.0.so.0+0x54e2e)
    #79 0x7fc5acd6f507 in g_main_context_iterate.constprop.0 (/lib64/libglib-2.0.so.0+0xa9507)
    #80 0x7fc5acd185f2 in g_main_context_iteration (/lib64/libglib-2.0.so.0+0x525f2)
    #81 0x7fc5b0ef8a47 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2f8a47)
    #82 0x7fc5b0ea5d61 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2a5d61)
    #83 0x7fc5b0ce89c9 in QThread::exec() (/lib64/libQt5Core.so.5+0xe89c9)
    #84 0x7fc5b0ce9bf8 in QThreadPrivate::start(void*) (/lib64/libQt5Core.so.5+0xe9bf8)
    #85 0x7fc5ace9f801 in start_thread (/lib64/libc.so.6+0x9f801)
    #86 0x7fc5ace3f44f in __GI___clone3 (/lib64/libc.so.6+0x3f44f)

0x602000dbc420 is located 0 bytes to the right of 16-byte region [0x602000dbc410,0x602000dbc420)
allocated by thread T7 (QThread) here:
    #0 0x7fc5b60b64d7 in operator new[](unsigned long) (/lib64/libasan.so.6+0xb64d7)
    #1 0x7fc5b32d2258 in std::_MakeUniq<long []>::__array std::make_unique<long []>(unsigned long) /usr/include/c++/11/bits/unique_ptr.h:968
    #2 0x7fc5b3b087eb in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2079
    #3 0x7fc5b3b06aab in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2106
    #4 0x7fc5b3aceabc in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2276
    #5 0x7fc5b38f665c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #6 0x7fc5b34da61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #7 0x7fc5b35c2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #8 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #9 0x7fc5b3947c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #10 0x7fc5b38bfd04 in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #11 0x7fc5b38fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #12 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #13 0x7fc5b38fb212 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #14 0x7fc5b341a04c in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #15 0x7fc5b38f85e9 in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #16 0x7fc5b36c8556 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #17 0x7fc5b36c83e7 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #18 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #19 0x7fc5b38e1c2a in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #20 0x7fc5b38e27d9 in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #21 0x7fc5b41cd611 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #22 0x7fc5b387f32d in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #23 0x7fc5b38f677c in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #24 0x7fc5b34da61a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #25 0x7fc5b35c2fd9 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #26 0x7fc5b394269c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #27 0x7fc5b3947c89 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #28 0x7fc5b38fa6c3 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #29 0x7fc5b395f4f4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120

Thread T7 (QThread) created by T0 here:
    #0 0x7fc5b60587d5 in pthread_create (/lib64/libasan.so.6+0x587d5)
    #1 0x7fc5b0ce969e in QThread::start(QThread::Priority) (/lib64/libQt5Core.so.5+0xe969e)

SUMMARY: AddressSanitizer: heap-buffer-overflow ../libinterp/corefcn/cellfun.cc:2088 in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int)
Shadow bytes around the buggy address:
  0x0c04801af830: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c04801af840: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c04801af850: fa fa fa fa fa fa fd fd fa fa fd fd fa fa 00 00
  0x0c04801af860: fa fa fd fd fa fa fa fa fa fa fa fa fa fa 00 00
  0x0c04801af870: fa fa fd fd fa fa 00 00 fa fa fd fd fa fa fd fd
=>0x0c04801af880: fa fa 00 00[fa]fa 00 fa fa fa fd fd fa fa fd fd
  0x0c04801af890: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fd
  0x0c04801af8a0: fa fa 00 00 fa fa fd fd fa fa fd fa fa fa fd fd
  0x0c04801af8b0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa 00 fa
  0x0c04801af8c0: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa 00 00
  0x0c04801af8d0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==300334==ABORTING


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 19 Feb 2023 11:47:48 AM UTC, comment #10: 

@Dmitri: Thanks for the backtrace with symbols and line numbers.

I pushed the following patch which avoids the crash for me:
https://hg.savannah.gnu.org/hgweb/octave/rev/0e046fefbffa

Markus Mützel <mmuetzel>
Group administrator
Sat 18 Feb 2023 06:56:21 PM UTC, comment #9: 

Running with ASAN I get:


octave:3> test libinterp/corefcn/cellfun.cc-tst
warning: inline is obsolete; use anonymous functions instead
=================================================================
==4032274==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602001021218 at pc 0x7eff116d7266 bp 0x7efeed2d87c0 sp 0x7efeed2d87b0
READ of size 8 at 0x602001021218 thread T7 (QThread)
    #0 0x7eff116d7265 in dim_vector::increment_index(long*, int) const ../liboctave/array/dim-vector.h:478
    #1 0x7eff116d9d62 in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2092
    #2 0x7eff116d7c19 in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2106
    #3 0x7eff1169fc02 in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2276
    #4 0x7eff114c6be2 in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #5 0x7eff110d229a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #6 0x7eff111bac77 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #7 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #8 0x7eff11518749 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #9 0x7eff1149028c in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #10 0x7eff114cac49 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #11 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #12 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #13 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #14 0x7eff114c8b6f in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #15 0x7eff11297de2 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #16 0x7eff11297c73 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #17 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #18 0x7eff114b21ae in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #19 0x7eff114b2d5d in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #20 0x7eff11d9f893 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #21 0x7eff1144f8b1 in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #22 0x7eff114c6d02 in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #23 0x7eff110d229a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #24 0x7eff111bac77 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #25 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #26 0x7eff11518749 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #27 0x7eff114cac49 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #28 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #29 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #30 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #31 0x7eff114cc35a in octave::tree_evaluator::visit_try_catch_command(octave::tree_try_catch_command&) ../libinterp/parse-tree/pt-eval.cc:4063
    #32 0x7eff115099be in octave::tree_try_catch_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:80
    #33 0x7eff114ca9eb in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #34 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #35 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #36 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #37 0x7eff114c9f38 in octave::tree_evaluator::visit_if_command_list(octave::tree_if_command_list&) ../libinterp/parse-tree/pt-eval.cc:3711
    #38 0x7eff114e1946 in octave::tree_if_command_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:111
    #39 0x7eff114c9b4f in octave::tree_evaluator::visit_if_command(octave::tree_if_command&) ../libinterp/parse-tree/pt-eval.cc:3689
    #40 0x7eff1152cbce in octave::tree_if_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-select.h:141
    #41 0x7eff114ca9eb in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #42 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #43 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #44 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #45 0x7eff114cd9ba in octave::tree_evaluator::visit_unwind_protect_command(octave::tree_unwind_protect_command&) ../libinterp/parse-tree/pt-eval.cc:4208
    #46 0x7eff11509a32 in octave::tree_unwind_protect_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-except.h:142
    #47 0x7eff114ca9eb in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #48 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #49 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #50 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #51 0x7eff114e5a19 in void octave::tree_evaluator::execute_range_loop<double>(octave::range<double, void> const&, int, octave::octave_lvalue&, octave::tree_statement_list*) (/home/dima/src/dev/octave/gcc_asan/libinterp/.libs/liboctinterp.so.11+0x14e5a19)
    #52 0x7eff114c369c in octave::tree_evaluator::visit_simple_for_command(octave::tree_simple_for_command&) ../libinterp/parse-tree/pt-eval.cc:3075
    #53 0x7eff11520360 in octave::tree_simple_for_command::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-loop.h:179
    #54 0x7eff114ca9eb in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3838
    #55 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #56 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #57 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #58 0x7eff114c8b6f in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #59 0x7eff11297de2 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #60 0x7eff11297c73 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #61 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #62 0x7eff11518749 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #63 0x7eff114cac49 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #64 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #65 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #66 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #67 0x7eff114b1b47 in octave::tree_evaluator::eval(std::shared_ptr<octave::tree_statement_list>&, bool) ../libinterp/parse-tree/pt-eval.cc:985
    #68 0x7eff114b0835 in octave::tree_evaluator::repl() ../libinterp/parse-tree/pt-eval.cc:804
    #69 0x7eff11d9e52c in octave::interpreter::main_loop() ../libinterp/corefcn/interpreter.cc:1316
    #70 0x7eff11d90fc6 in octave::interpreter::execute() ../libinterp/corefcn/interpreter.cc:882
    #71 0x7eff13116bbc in octave::interpreter_qobject::execute() ../libgui/src/interpreter-qobject.cc:87
    #72 0x7eff1339f456 in octave::interpreter_qobject::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) libgui/src/moc-interpreter-qobject.cc:88
    #73 0x7eff0ead1a98 in QObject::event(QEvent*) (/lib64/libQt5Core.so.5+0x2d1a98)
    #74 0x7eff0f7ae422 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/lib64/libQt5Widgets.so.5+0x1ae422)
    #75 0x7eff1321ecec in octave::octave_qapplication::notify(QObject*, QEvent*) ../libgui/src/octave-qobject.cc:146
    #76 0x7eff0eaa7357 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/lib64/libQt5Core.so.5+0x2a7357)
    #77 0x7eff0eaaa8b5 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (/lib64/libQt5Core.so.5+0x2aa8b5)
    #78 0x7eff0eaf8fa6 in postEventSourceDispatch(_GSource*, int (*)(void*), void*) (/lib64/libQt5Core.so.5+0x2f8fa6)
    #79 0x7eff0871ae2e in g_main_context_dispatch (/lib64/libglib-2.0.so.0+0x54e2e)
    #80 0x7eff0876f507 in g_main_context_iterate.constprop.0 (/lib64/libglib-2.0.so.0+0xa9507)
    #81 0x7eff087185f2 in g_main_context_iteration (/lib64/libglib-2.0.so.0+0x525f2)
    #82 0x7eff0eaf8a47 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2f8a47)
    #83 0x7eff0eaa5d61 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/lib64/libQt5Core.so.5+0x2a5d61)
    #84 0x7eff0e8e89c9 in QThread::exec() (/lib64/libQt5Core.so.5+0xe89c9)
    #85 0x7eff0e8e9bf8 in QThreadPrivate::start(void*) (/lib64/libQt5Core.so.5+0xe9bf8)
    #86 0x7eff0889f801 in start_thread (/lib64/libc.so.6+0x9f801)
    #87 0x7eff0883f44f in __GI___clone3 (/lib64/libc.so.6+0x3f44f)

0x602001021218 is located 0 bytes to the right of 8-byte region [0x602001021210,0x602001021218)
allocated by thread T7 (QThread) here:
    #0 0x7eff13cb64d7 in operator new[](unsigned long) (/lib64/libasan.so.6+0xb64d7)
    #1 0x7eff10ec9e46 in std::_MakeUniq<long []>::__array std::make_unique<long []>(unsigned long) /usr/include/c++/11/bits/unique_ptr.h:968
    #2 0x7eff116d994b in Cell octave::do_mat2cell_nd<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2079
    #3 0x7eff116d7c19 in Cell octave::do_mat2cell<NDArray>(NDArray const&, Array<long, std::allocator<long> > const*, int) ../libinterp/corefcn/cellfun.cc:2106
    #4 0x7eff1169fc02 in octave::Fmat2cell(octave_value_list const&, int) ../libinterp/corefcn/cellfun.cc:2276
    #5 0x7eff114c6be2 in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3362
    #6 0x7eff110d229a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #7 0x7eff111bac77 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #8 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #9 0x7eff11518749 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #10 0x7eff1149028c in octave::tree_simple_assignment::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-assign.cc:101
    #11 0x7eff114cac49 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #12 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120
    #13 0x7eff114cb798 in octave::tree_evaluator::visit_statement_list(octave::tree_statement_list&) ../libinterp/parse-tree/pt-eval.cc:3948
    #14 0x7eff11011c3a in octave::tree_statement_list::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:193
    #15 0x7eff114c8b6f in octave::tree_evaluator::execute_user_function(octave_user_function&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3587
    #16 0x7eff11297de2 in octave_user_function::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:495
    #17 0x7eff11297c73 in octave_user_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-usr-fcn.cc:488
    #18 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #19 0x7eff114b21ae in octave::tree_evaluator::eval_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int&, int) ../libinterp/parse-tree/pt-eval.cc:1053
    #20 0x7eff114b2d5d in octave::tree_evaluator::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/parse-tree/pt-eval.cc:1112
    #21 0x7eff11d9f893 in octave::interpreter::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ../libinterp/corefcn/interpreter.cc:1478
    #22 0x7eff1144f8b1 in octave::Feval(octave::interpreter&, octave_value_list const&, int) ../libinterp/parse-tree/oct-parse.yy:6466
    #23 0x7eff114c6d02 in octave::tree_evaluator::execute_builtin_function(octave_builtin&, int, octave_value_list const&) ../libinterp/parse-tree/pt-eval.cc:3367
    #24 0x7eff110d229a in octave_builtin::execute(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-builtin.cc:49
    #25 0x7eff111bac77 in octave_function::call(octave::tree_evaluator&, int, octave_value_list const&) ../libinterp/octave-value/ov-fcn.cc:57
    #26 0x7eff1151315c in octave::tree_index_expression::evaluate_n(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.cc:427
    #27 0x7eff11518749 in octave::tree_index_expression::evaluate(octave::tree_evaluator&, int) ../libinterp/parse-tree/pt-idx.h:104
    #28 0x7eff114cac49 in octave::tree_evaluator::visit_statement(octave::tree_statement&) ../libinterp/parse-tree/pt-eval.cc:3863
    #29 0x7eff1152ffb4 in octave::tree_statement::accept(octave::tree_walker&) ../libinterp/parse-tree/pt-stmt.h:120

Thread T7 (QThread) created by T0 here:
    #0 0x7eff13c587d5 in pthread_create (/lib64/libasan.so.6+0x587d5)
    #1 0x7eff0e8e969e in QThread::start(QThread::Priority) (/lib64/libQt5Core.so.5+0xe969e)

SUMMARY: AddressSanitizer: heap-buffer-overflow ../liboctave/array/dim-vector.h:478 in dim_vector::increment_index(long*, int) const
Shadow bytes around the buggy address:
  0x0c04801fc1f0: fa fa fd fd fa fa fa fa fa fa fd fd fa fa fa fa
  0x0c04801fc200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fd fd
  0x0c04801fc210: fa fa fa fa fa fa fd fd fa fa fa fa fa fa fa fa
  0x0c04801fc220: fa fa fd fd fa fa fa fa fa fa fd fd fa fa fd fd
  0x0c04801fc230: fa fa fd fa fa fa fd fd fa fa 00 00 fa fa 00 fa
=>0x0c04801fc240: fa fa 00[fa]fa fa fd fd fa fa 00 00 fa fa fd fa
  0x0c04801fc250: fa fa 00 fa fa fa 00 00 fa fa fd fd fa fa 00 00
  0x0c04801fc260: fa fa fd fd fa fa 00 00 fa fa fd fa fa fa fd fd
  0x0c04801fc270: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa fd fd
  0x0c04801fc280: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fd
  0x0c04801fc290: fa fa 00 00 fa fa fd fd fa fa fd fd fa fa fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==4032274==ABORTING


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sat 18 Feb 2023 04:45:56 PM UTC, comment #8: 

Also crashes with a build with MXE Octave. And I managed to get a backtrace with gdb.
See the attachment.


(file #54380)

Markus Mützel <mmuetzel>
Group administrator
Sat 18 Feb 2023 01:41:33 PM UTC, comment #7: 

The MINGW64 runner started crashing on the tests in cellfun.cc-tst since this change was committed:
https://github.com/gnu-octave/octave/actions/runs/4094439123/jobs/7060648744#step:14:69


D:/a/octave/octave/.build/src/.libs/octave.exe: Arg list too long
make[4]: *** [Makefile:2880: check-local] Error 127
  libinterp\corefcn\cellfun.cc-tst ...............................make[4]: Leaving directory '/d/a/octave/octave/.build/test'
make[3]: *** [Makefile:2732: check-am] Error 2
make[3]: Leaving directory '/d/a/octave/octave/.build/test'
make[2]: *** [Makefile:2734: check] Error 2
make[2]: Leaving directory '/d/a/octave/octave/.build/test'
make[1]: *** [Makefile:27911: check-recursive] Error 1
make[1]: Leaving directory '/d/a/octave/octave/.build'
make: *** [Makefile:28209: check] Error 2
make: Leaving directory '/d/a/octave/octave/.build'
Error: Process completed with exit code 2.


Also crashes for me when I build locally.

Unfortunately, it looks like gdb isn't able to catch the crash. Octave just exists, and gdb tells me that no process is running for which a backtrace could be shown.

It was working with the changes that got reverted.

To be honest, I don't understand the part of the code that you modified. (There is not a single line of comment in that function that might give a hint at what it's doing...)
So, I can't really evaluate what might be causing that crash...

Markus Mützel <mmuetzel>
Group administrator
Sun 05 Feb 2023 01:58:53 AM UTC, comment #6: 

No comments, so I checked in the smaller implementation here: http://hg.savannah.gnu.org/hgweb/octave/rev/90ce081eb281.

Marking as Fixed again and re-closing report.

Rik <rik5>
Group administrator
Wed 01 Feb 2023 05:51:09 PM UTC, comment #5: 

Re-opening report as I think this issue has a simpler fix.  Rather than changing Fmat2cell so that all trailing dimensions are specified before calling mat2cell(), it is enough to fix one line in do_mat2cell() which incorrectly allowed a dimension vector with zero columns to be created.  Patch is attached for that.  I also re-titled the bug report to what I believe is the true issue.

In order to test, use 'hg backout 8c57434587c9' and then apply the patch from this report.  If this patch works then the documentation changes and BIST test from the original changeset can be incorporated into this patch.

(file #54293)

Rik <rik5>
Group administrator
Sun 22 Jan 2023 11:09:07 AM UTC, comment #4: 

CI passed without new errors after this change.

Closing as fixed.

Markus Mützel <mmuetzel>
Group administrator
Sat 21 Jan 2023 12:27:23 PM UTC, comment #3: 

I pushed the patch to the default branch here:
https://hg.savannah.gnu.org/hgweb/octave/rev/8c57434587c9

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Thu 19 Jan 2023 07:36:30 PM UTC, comment #2: 

confirmed on Windows in 8.0.1 as well. have not tested in 9.0.1 yet.

does anyone know if this is changed behavior of mat2cell? while a mat2cell(A,r) form is given in the octave help, it appears that it is expecting r to be a constant. the help is a bit vague, though: "Given a single dimensional argument r". matlab help for mat2cell suggests that r should be able to be a vector of dimensions as given in the example below.   keeping this as 'Matlab Compatibility' for now until we determine whether or not it's a changed feature and it should be reassigned as a Feature Request.

Nicholas Jankowski <nrjank>
Group Member
Thu 19 Jan 2023 07:18:01 PM UTC, comment #1: 

The attached patch allows omitting values for trailing dimensions for me.

Haven't done much testing yet though...

(file #54251)

Markus Mützel <mmuetzel>
Group administrator
Thu 19 Jan 2023 10:34:12 AM UTC, original submission:  

I found that mat2cell is not working as I would expected when the rank of the array is >2.

In the following example I want to split an array of 4x2x2 along the first dimension and I would expect a cell containing two matrices of 2x2x2


octave> z = reshape(1:16,4,2,2)
z =

ans(:,:,1) =

   1   5
   2   6
   3   7
   4   8

ans(:,:,2) =

    9   13
   10   14
   11   15
   12   16

octave> mat2cell(z,[2,2])
ans = {}(2x0)



I would expect this


>> m = mat2cell(z,[2,2])

m =

  2×1 cell array

    {2×2×2 double}
    {2×2×2 double}

>> m{1}

ans(:,:,1) =

     1     5
     2     6


ans(:,:,2) =

     9    13
    10    14

>> m{2}

ans(:,:,1) =

     3     7
     4     8


ans(:,:,2) =

    11    15
    12    16


OS: Fedora 37 KDE
Octave version: 7.2.0
Installation method: Fedora RPM package


Mario Storti <mstorti>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #54380:  sigtrap-cellfun.txt added by mmuetzel (22KiB - text/plain)
file #54293:  patch.63682 added by rik5 (804B - application/octet-stream)

 

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 (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by mstorti (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 25 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-02-25 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2023-02-19 rik5 StatusIn Progress Ready For Test
    2023-02-19 mmuetzel StatusReady For Test In Progress
    2023-02-19 mmuetzel StatusNone Ready For Test
    2023-02-18 mmuetzel Attached File- Added sigtrap-cellfun.txt, #54380
    2023-02-18 mmuetzel StatusFixed None
        Open/ClosedClosed Open
    2023-02-05 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2023-02-01 rik5 Open/ClosedClosed Open
        Summarymat2cell returns incorrect vale for ndims&gt;2 mat2cell returns incorrect value when only one output dimensions is specified and input is N-D array
    2023-02-01 rik5 Attached File- Added patch.63682, #54293
        StatusFixed Patch Submitted
    2023-01-22 mmuetzel StatusReady For Test Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 9.1.0
    2023-01-21 mmuetzel StatusPatch Submitted Ready For Test
    2023-01-19 nrjank StatusConfirmed Patch Submitted
        Planned ReleaseNone 9.1.0
    2023-01-19 nrjank StatusPatch Submitted Confirmed
        Release7.2.0 8.0.90
        Planned Release9.1.0 None
    2023-01-19 mmuetzel Attached File- Added bug63682-mat2cell-no-trailing-dims.patch, #54251
        StatusNone Patch Submitted

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code