tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
330 stars 97 forks source link

nbytes and data_size wrong for complex arrays in matvar #184

Closed cbuchner1 closed 2 years ago

cbuchner1 commented 2 years ago

Hi,

I recently ran into an issue with the matio-1.5.21 library, trying to read a double complex Matlab array of size 32x1x1024

Here is a dump of some fields of the matvar dims[0]=32 dims[1]=1 dims[2]=1024 nbytes= 262144 data_size= 8 isComplex= 2048

Assuming the array is of double complex type, shouldn't data_size be 16 for one element, i.e. 2 * sizeof(double) ?

The nbytes therefore is undersized by a factor of 2 and a memcpy operation into an appropriately sized buffer (in my case an Eigen::Tensor from the Eigen matrix library intended to store that data) causes a segfault.

Christian

cbuchner1 commented 2 years ago

could this be because of split complex storage with separate Re and Im arrays?

tbeu commented 2 years ago

You can call Mat_VarGetSize to get the expected number of bytes.