bugGNU Octave - Bugs: bug #61280, mxDuplicateArray(...) has invalid...

 
 

bug #61280: mxDuplicateArray(...) has invalid write for sparse arrays, as reported by valgrind.

Submitter:  Quazgar <quazgar>
Submitted:  Mon 04 Oct 2021 03:14:34 PM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 07 Oct 2021 02:44:50 AM UTC, comment #5: 

Thank you for checking again and the great attached test 👍

Using the Octave "stable" and "default" development branch (without Docker on openSUSE Leap 15.3), I could not reproduce the problem.  valgrind does not complain about the mex function for me.

If someone can reproduce this issue with a newer version of Octave, this report can be reopened again.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 06 Oct 2021 07:21:05 AM UTC, comment #4: 

comment #3:

> Yes of course, I just attached a small minimal example
> ...


Oops, pressed enter too early.

This example works for 4.4.1, I could indeed not reproduce the behavior it with Octave 6.2.0 (on a fresh Docker image with Debian 11).

For the reference, this is the core of the code example:


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  auto orig = mxCreateSparse(0, 0, 0, mxREAL);
  auto dup = mxDuplicateArray(orig);
}


Quazgar <quazgar>
Wed 06 Oct 2021 07:13:27 AM UTC, comment #3: 

Yes of course, I just attached a small minimal example

seconds = 3600 *days * 24;
_printf (_("Enter something:"));


(file #52048)

Quazgar <quazgar>
Wed 06 Oct 2021 01:23:18 AM UTC, comment #2: 

Thanks for the report 👍

Do you have the opportunity to test your code with a newer version of Octave as Dmitri suggested in comment #1?

In any case it would be great if you could attach a (part of) your C MEX code you are working with and short instructions how you obtained the valgrind report 🙂  Then another maintainer can check if this problem still persists.

Kai Torben Ohlhus <siko1056>
Group Member
Mon 04 Oct 2021 03:24:38 PM UTC, comment #1: 

octave 4.4.1 is ancient and not supported. Please try 6.3.0.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 04 Oct 2021 03:14:34 PM UTC, original submission:  

In mex code written by me, valgrind reports this:


[... debugging output indicating that this is a sparse array ...]
==23101== Thread 19 QThread:
==23101== Invalid write of size 8
==23101==    at 0x483C980: memmove (vg_replace_strmem.c:1270)
==23101==    by 0x59466BB: mxArray_sparse::dup() const (in /usr/lib/x86_64-linux-gnu/liboctinterp.so.6.0.0)
==23101==    by 0x593BA38: mxDuplicateArray (in /usr/lib/x86_64-linux-gnu/liboctinterp.so.6.0.0)
[... frames by my code ...]
==23101==  Address 0x3d24fef0 is 0 bytes after a block of size 0 alloc'd
==23101==    at 0x483577F: malloc (vg_replace_malloc.c:299)
==23101==    by 0x5939FBE: mxArray::malloc(unsigned long) (in /usr/lib/x86_64-linux-gnu/liboctinterp.so.6.0.0)
==23101==    by 0x59465FE: mxArray_sparse::dup() const (in /usr/lib/x86_64-linux-gnu/liboctinterp.so.6.0.0)
==23101==    by 0x593BA38: mxDuplicateArray (in /usr/lib/x86_64-linux-gnu/liboctinterp.so.6.0.0)
[... frames by my code ...]


The code did not crash so far, but this does not look quite good.

mxDuplicateArray gets mxArray pointers, and when they point to empty, sparse arrays, this behavior occurs.  The array in question was created like this:


mxArray *array = mxCreateSparse(0, 0, 0, mxREAL);


Quazgar <quazgar>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #52048:  issue_61280.tar.gz added by quazgar (516B - application/gzip - Minimal example.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-10-07 siko1056 StatusNeed Info Works For Me
        Open/ClosedOpen Closed
    2021-10-06 quazgar Attached File- Added issue_61280.tar.gz, #52048
    2021-10-06 siko1056 CategoryNone Libraries
    2021-10-05 rik5 StatusNone Need Info
    2021-10-04 quazgar Carbon-Copy- Added quazgar

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code