bugGNU Octave - Bugs: bug #52365, Octave crashes when solving a...

 
 

bug #52365: Octave crashes when solving a sparse system of linear equations (U = K \ R)

Submitter:  None
Submitted:  Wed 08 Nov 2017 10:10:17 AM UTC
   
 
Category:  Interpreter Severity:  4 - Important
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  None
Originator Name:  Lagrange Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 15 Nov 2017 11:35:46 PM UTC, comment #8: 

I fixed the issue on stable in time for the 4.2.2 release here (http://hg.savannah.gnu.org/hgweb/octave/rev/4283c4c2fcb6).  I also pulled the change across to the default branch and updated it to use nullptr rather than 0.

Rik <rik5>
Group administrator
Tue 14 Nov 2017 01:45:34 AM UTC, comment #7: 

This could also be a bug that should be fixed before the 4.2.2 release.

Rik <rik5>
Group administrator
Tue 14 Nov 2017 01:44:43 AM UTC, comment #6: 

The problem seems to be very subtle.  The  xtype and data pointer for the B matrix are set by this code.


          B->xtype = CHOLMOD_REAL;

          if (b.rows () < 1 || b.cols () < 1)
            B->x = &dummy;
          else
            B->x = b.data ();


Later on within the SuiteSparse library there is an if test on this codition


    ((A)->xtype != CHOLMOD_PATTERN && ((A)->x) == NULL) || \


The problem occurs when the Sparse matrix is empty.  In this case, because there is no data to store, the data pointer is NULL.  That causes SuiteSparse to eventually fail.  Apparently this problem has been encountered before.  The test for rows or columns less than one looks like it is designed to find empty matrices, and replace the nullptr with a dummy pointer to a valid region.

I replaced the code above with



 B->x = b.data ();
 if (B->x == 0x0)
   B->x = &dummy;


This works and the code no longer segfaults.  The question is whether this is okay in all situations.  I think it is, but I'm adding jwe to the CC list so he can comment on this change.

If it is okay, it should be implemented in 4 different instances in dSparse.cc and 4 more in CSparse.cc on the stable branch.  On the default branch, the comparison to 0x0 should be replaced with a comparison to nullptr.


Rik <rik5>
Group administrator
Fri 10 Nov 2017 05:11:09 PM UTC, comment #5: 

The mex interface of suitesparse works in matlab for the given example. So, it seems to me that the problem is in the call. Line 88 of cholmod_spsolve (responsable of the error message) is


RETURN_IF_XTYPE_INVALID (B, CHOLMOD_REAL, CHOLMOD_ZOMPLEX, NULL) ;


and


#define RETURN_IF_XTYPE_INVALID(A,xtype1,xtype2,result) \
{ \
    if ((A)->xtype < (xtype1) || (A)->xtype > (xtype2) || \
        ((A)->xtype != CHOLMOD_PATTERN && ((A)->x) == NULL) || \
        ((A)->xtype == CHOLMOD_ZOMPLEX && ((A)->z) == NULL)) \
    { \
        if (Common->status != CHOLMOD_OUT_OF_MEMORY) \
        { \
            ERROR (CHOLMOD_INVALID, "invalid xtype") ; \
        } \
        return (result) ; \
    } \
}


What is B->x = b.data () when b is a sparse zeros matrix?

Marco Caliari <caliari>
Group Member
Fri 10 Nov 2017 04:12:42 PM UTC, comment #4: 

Here is a backtrace:

#0  0x00007ffff5ef08a5 in SparseMatrix::fsolve (this=0x7fffffffaf80, mattype=..., b=..., err=@0x7fffffffae48: 0,
    rcond=@0x7fffffffae40: 0.036477512569622478, sing_handler=0x7ffff77e5707 <solve_singularity_warning(double)>,
    calc_cond=true) at ../liboctave/array/dSparse.cc:6064
#1  0x00007ffff5ef3b86 in SparseMatrix::solve (this=0x7fffffffaf80, mattype=..., b=..., err=@0x7fffffffae48: 0,
    rcond=@0x7fffffffae40: 0.036477512569622478, sing_handler=0x7ffff77e5707 <solve_singularity_warning(double)>,
    singular_fallback=true) at ../liboctave/array/dSparse.cc:6831
#2  0x00007ffff77e702d in xleftdiv (a=..., b=..., typ=...) at ../libinterp/corefcn/sparse-xdiv.cc:495
#3  0x00007ffff705b738 in oct_binop_ldiv (a1=..., a2=...) at ../libinterp/operators/op-sm-sm.cc:122
#4  0x00007ffff72cc69b in do_binary_op (op=octave_value::op_ldiv, v1=..., v2=...) at ../libinterp/octave-value/ov.cc:2186
#5  0x00007ffff738f1aa in octave::tree_evaluator::visit_binary_expression (this=0x62f130, expr=...)
    at ../libinterp/parse-tree/pt-eval.cc:232
#6  0x00007ffff7388fc8 in octave::tree_binary_expression::accept (this=0x7de190, tw=...)
    at ../libinterp/parse-tree/pt-binop.h:110
#7  0x00007ffff721ddfa in octave::tree_evaluator::evaluate (this=0x62f130, expr=0x7de190, nargout=1)
    at ../libinterp/parse-tree/pt-eval.h:271
#8  0x00007ffff7396ed0 in octave::tree_evaluator::visit_simple_assignment (this=0x62f130, expr=...)
    at ../libinterp/parse-tree/pt-eval.cc:2087
#9  0x00007ffff7388950 in octave::tree_simple_assignment::accept (this=0x7de1d0, tw=...)
    at ../libinterp/parse-tree/pt-assign.h:83
#10 0x00007ffff721ddfa in octave::tree_evaluator::evaluate (this=0x62f130, expr=0x7de1d0, nargout=0)
    at ../libinterp/parse-tree/pt-eval.h:271
#11 0x00007ffff739772d in octave::tree_evaluator::visit_statement (this=0x62f130, stmt=...)
    at ../libinterp/parse-tree/pt-eval.cc:2211
#12 0x00007ffff73baee0 in octave::tree_statement::accept (this=0x7de210, tw=...) at ../libinterp/parse-tree/pt-stmt.h:112
#13 0x00007ffff73978ba in octave::tree_evaluator::visit_statement_list (this=0x62f130, lst=...)
    at ../libinterp/parse-tree/pt-eval.cc:2253
#14 0x00007ffff721e234 in octave::tree_statement_list::accept (this=0x84db20, tw=...) at ../libinterp/parse-tree/pt-stmt.h:187
#15 0x00007ffff72b3229 in octave_user_script::call (this=0x7f5400, tw=..., nargout=0, args=...)
    at ../libinterp/octave-value/ov-usr-fcn.cc:216
---Type <return> to continue, or q <return> to quit---
#16 0x00007ffff73921e8 in octave::tree_evaluator::visit_identifier (this=0x62f130, expr=...)
    at ../libinterp/parse-tree/pt-eval.cc:1010
#17 0x00007ffff7371636 in octave::tree_identifier::accept (this=0xa1d610, tw=...) at ../libinterp/parse-tree/pt-id.h:128
#18 0x00007ffff721ddfa in octave::tree_evaluator::evaluate (this=0x62f130, expr=0xa1d610, nargout=0)
    at ../libinterp/parse-tree/pt-eval.h:271
#19 0x00007ffff739772d in octave::tree_evaluator::visit_statement (this=0x62f130, stmt=...)
    at ../libinterp/parse-tree/pt-eval.cc:2211
#20 0x00007ffff73baee0 in octave::tree_statement::accept (this=0x77f0d0, tw=...) at ../libinterp/parse-tree/pt-stmt.h:112
#21 0x00007ffff73978ba in octave::tree_evaluator::visit_statement_list (this=0x62f130, lst=...)
    at ../libinterp/parse-tree/pt-eval.cc:2253
#22 0x00007ffff721e234 in octave::tree_statement_list::accept (this=0x80f780, tw=...) at ../libinterp/parse-tree/pt-stmt.h:187
#23 0x00007ffff76b38c0 in octave::interpreter::main_loop (this=0x62ed80) at ../libinterp/corefcn/interpreter.cc:974
#24 0x00007ffff76b2771 in octave::interpreter::execute (this=0x62ed80) at ../libinterp/corefcn/interpreter.cc:695
#25 0x00007ffff6e79973 in octave::cli_application::execute (this=0x7fffffffc4b0) at ../libinterp/octave.cc:384
#26 0x000000000040184a in main (argc=9, argv=0x7fffffffc7d8) at ../src/main-cli.cc:90
(gdb)

Dmitri A. Sergatskov <dasergatskov>
Fri 10 Nov 2017 11:05:23 AM UTC, comment #3: 

It works in Matlab, is works with full(mat_ass.R) (mat_ass.R is a matrix of zeros), it works with mat_ass.R=sprand(1224,100,rand).

Marco Caliari <caliari>
Group Member
Fri 10 Nov 2017 06:25:46 AM UTC, comment #2: 

The error is in the SuiteSparse library that Octave is calling.  This may be an upstream error with that library, or maybe Octave is not calling the function properly.

Rik <rik5>
Group administrator
Fri 10 Nov 2017 05:47:19 AM UTC, comment #1: 

Confirmed.  And it happens with the development version of Octave as well.  I did my testing on a Linux machine so this is not unique to Windows.

Rik <rik5>
Group administrator
Wed 08 Nov 2017 10:10:17 AM UTC, original submission:  

Dear Octave users and developers,

If you run the octave script in the attached file, you get the following output:

$ octave octave_cholmod_sparse.m
warning: warning -4, at line 88 in file /cygdrive/e/cyg_pub/devel/suitesparse/build_4.5.1/cholmod-3.0.9-1.x86_64/src/cholmod-3.0.9/Cholesky/cholmod_spsolve.c: invalid xtype
warning: called from
    octave_cholmod_sparse at line 6 column 3

After that octave crashes:

Program received signal SIGSEGV, Segmentation fault.
0x00000003de0f36cb in cygoctave-4!_ZNK12SparseMatrix6fsolveER10MatrixTypeRKS_RiR                                                                                                                                                                                                          dPFvdEb () from /usr/bin/cygoctave-4.dll

(gdb) bt full
No symbol table info available.#0  0x00000003de0f36cb in cygoctave-4!SparseMatrix::fsolve(MatrixType&, SparseMatrix const&, int&, double&, void (*)(double), bool) const () from /usr/bin/cygoctave-4.dll
No symbol table info available.
#1  0x00000003de0f90b8 in cygoctave-4!SparseMatrix::solve(MatrixType&, SparseMatrix const&, int&, double&, void (*)(double), bool) const () from /usr/bin/cygoctave-4.dll
No symbol table info available.
#2  0x00000003dd7692e5 in cygoctinterp-4!xleftdiv(SparseMatrix const&, SparseMatrix const&, MatrixType&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#3  0x00000003dd1714de in cygoctinterp-4!install_sm_sm_ops() () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#4  0x00000003dd35bbb0 in cygoctinterp-4!do_binary_op(octave_value::binary_op, octave_value const&, octave_value const&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#5  0x00000003dd3a9166 in cygoctinterp-4!tree_binary_expression::rvalue1(int) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#6  0x00000003dd3a4f36 in cygoctinterp-4!tree_simple_assignment::rvalue1(int) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#7  0x00000003dd3b4122 in cygoctinterp-4!octave::tree_evaluator::visit_statement(tree_statement&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#8  0x00000003dd3b38a9 in cygoctinterp-4!octave::tree_evaluator::visit_statement_list(tree_statement_list&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#9  0x00000003dd352567 in cygoctinterp-4!octave_user_script::do_multi_index_op(int, octave_value_list const&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#10 0x00000003dd39cc77 in cygoctinterp-4!source_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#11 0x00000003dd6551a3 in cygoctinterp-4!recover_from_exception() () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#12 0x00000003dd6562c6 in cygoctinterp-4!octave::interpreter::execute_command_line_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#13 0x00000003dd65b2eb in cygoctinterp-4!octave::interpreter::execute() () from /usr/bin/cygoctinterp-4.dll
No symbol table info available.
#14 0x0000000100401913 in ?? ()
No symbol table info available.
#15 0x0000000180047812 in _cygwin_exit_return () from /usr/bin/cygwin1.dll
No symbol table info available.
#16 0x00000001800455e3 in _cygtls::call2(unsigned int ()(void, void*), void*, void*) () from /usr/bin/cygwin1.dll
No symbol table info available.
#17 0x0000000180045694 in _cygtls::call(unsigned int ()(void, void*), void*) () from /usr/bin/cygwin1.dll
No symbol table info available.
#18 0x0000000000000000 in ?? ()
No symbol table info
available.

This bug also occurs in the native Windows build version 4.0.0 and 4.2.1.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #42347:  octave_cholmod_sparse.m added by None (134B - application/octet-stream)
file #42348:  octave_cholmod_sparse.mat added by None (1009KiB - 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 rik5
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by caliari (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  •  

    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
    2017-11-15 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2017-11-14 rik5 StatusConfirmed In Progress
        Carbon-Copy- Added jwe
    2017-11-10 rik5 Severity3 - Normal 4 - Important
        StatusNone Confirmed
        Operating SystemMicrosoft Windows Any
    2017-11-08 None Attached File- Added octave_cholmod_sparse.m, #42347
        Attached File- Added octave_cholmod_sparse.mat, #42348

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code