bugGNU Octave - Bugs: bug #56711, Three input form of diag can...

 
 

bug #56711: Three input form of diag can segfault if a cell array is passed

Submitter:  Travis Arnold <teerav42>
Submitted:  Fri 02 Aug 2019 09:58:04 PM UTC
 
Category:  Octave Function Severity:  3 - Normal
Priority:  7 - High Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.1.0 Operating System:  * GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Tue 06 Aug 2019 12:57:52 AM UTC, comment #4: 

I fixed the issue in this cset https://hg.savannah.gnu.org/hgweb/octave/rev/1582a6140275.  This was done on the stable branch and will be part of the next bug fix release of Octave.

Rik <rik5>
Project Administrator
Mon 05 Aug 2019 11:26:34 PM UTC, comment #3: 

Here is a backtrace of the segfault.

0x00007f07b9270637 in octave::refcount<long>::operator-- (
    this=0x7f07b9071250 <vtable for octave::tree_identifier+24>)
    at ./liboctave/util/oct-refcount.h:96
96            return OCTAVE_ATOMIC_DECREMENT (&m_count);
(gdb) bt
#0  0x00007f07b9270637 in octave::refcount<long>::operator-- (
    this=0x7f07b9071250 <vtable for octave::tree_identifier+24>)
    at ./liboctave/util/oct-refcount.h:96
#1  0x00007f07b92700d8 in octave_value::operator= (this=0x7f07802f4130, a=...)
    at ./libinterp/octave-value/ov.h:360
#2  0x00007f07b831cbc2 in Array<octave_value>::diag (this=0x7f07803b04b0, m=2, n=1)
    at ./liboctave/array/Array.cc:2621
#3  0x00007f07b860d753 in Cell::diag (this=0x7f07803b04b0, m=2, n=1)
    at libinterp/corefcn/Cell.cc:354
#4  0x00007f07b83fd82c in octave_base_matrix<Cell>::diag (this=0x7f07803b04a0, m=2, n=1)
    at libinterp/octave-value/ov-base-mat.h:136
#5  0x00007f07b86e3eaf in octave_value::diag (this=0x7f078ea00310, m=2, n=1)
    at ./libinterp/octave-value/ov.h:1311
#6  0x00007f07b86bd959 in Fdiag (args=...) at libinterp/corefcn/data.cc:1237

Of course, it's not at all where I expected it to be.

Rik <rik5>
Project Administrator
Sat 03 Aug 2019 04:48:51 PM UTC, comment #2: 

Rik, your point stands regardless, but to be clear: based on the behavior when using numerical arrays, I believe that the example I gave that segfaulted did have valid input, and therefore it should neither segfault (obviously) nor give an error.

Travis Arnold <teerav42>
Sat 03 Aug 2019 03:31:08 AM UTC, comment #1: 

Confirmed.  The segfault is still present on the current stable release, 5.1.0.  Even if the input is invalid, the interpreter should merely flag an error--never segfault.  I have raised the priority to high.

Rik <rik5>
Project Administrator
Fri 02 Aug 2019 09:58:04 PM UTC, original submission:  

I am running Octave 4.4.1 on Xubuntu 19.04. Example:

diag([1, 1], 2, 1)

returns

ans =

Diagonal Matrix

   1
   0

which is fine (although now that I look at it perhaps that is also a small bug, as that matrix is not diagonal if one subscribes to the convention that only square matrices may be labeled diagonal; I digress however).

In contrast,

diag({1, 1}, 2, 1)

results in a segfault:

fatal: caught signal Segmentation fault -- stopping myself...
Segmentation fault (core dumped)

This seems to occur when the first argument is a cell array and either M or N (the second and third arguments, respectively) is less than the number of elements in the cell.

Matlab compatibility is not a concern here, as Matlab's version of diag does not support cell arrays or the three input version (in fact, the way I found this bug was by reimplementing a version of diag for Matlab so that it does support these features).

Travis Arnold <teerav42>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    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 project members can vote.

     

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-08-06 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-08-03 rik5 Priority5 - Normal 7 - High
        StatusNone Confirmed
        Release4.4.1 5.1.0
    2019-08-02 teerav42 Carbon-Copy- Added -email is unavailable-

    Back to the top


    Powered by Savane 3.9