tbeu / matio

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

Call to Mat_GetDir results in HDF5 stack smashing #138

Closed SteScheller closed 4 years ago

SteScheller commented 4 years ago

Hi,

I use matio 1.5.16 to load a .mat-file and try to query the variable names with the following code:

std::cout << "Input file: " << input << std::endl;
mat_t *modelParameters = Mat_Open(input.c_str(), 0);

// print some file information
{
    int major, minor, release;
    Mat_GetLibraryVersion(&major, &minor, &release);
    std::printf("matio version: %i.%i.%i\n", major, minor, release);
    std::cout << "parameter file header: " << Mat_GetHeader(modelParameters) << std::endl;
}

size_t numVars = 0;
char** varNames = nullptr;
varNames = Mat_GetDir(modelParameters, &numVars);

for (size_t i = 0; i < numVars; ++i)
{
    if (i == 0) std::cout << "Variable Names:\n" << std::endl;
    std::cout << varNames[i] << std::endl;
}

Mat_Close(modelParameters);

This is the relevant output of the program:

Input file: /mnt/local/data/geotherm/SFB1313_Demonstrator/aPC_ResponseSurface.mat                                                                                                             
matio version: 1.5.16                                                                                                                                                                         
parameter file header: MATLAB 7.3 MAT-file, Platform: PCWIN64, Created on: Thu Apr 02 12:27:05 2020 HDF5 schema 1.00 .                                                                        
HDF5-DIAG: Error detected in HDF5 (1.12.0) thread 0:                                                                                                                                          
  #000: H5G.c line 528 in H5Gopen2(): unable to open group                                                                                                                                    
    major: Symbol table                                                                                                                                                                       
    minor: Can't open object                                                                                                                                                                  
  #001: H5VLcallback.c line 4186 in H5VL_group_open(): group open failed                                                                                                                      
    major: Virtual Object Layer                                                                                                                                                               
    minor: Can't open object                                                                                                                                                                  
  #002: H5VLcallback.c line 4153 in H5VL__group_open(): group open failed                                                                                                                     
    major: Virtual Object Layer                                                                                                                                                               
    minor: Can't open object                                                                                                                                                                  
  #003: H5VLnative_group.c line 125 in H5VL__native_group_open(): unable to open group                                                                                                        
    major: Symbol table                                                                                                                                                                       
    minor: Can't open object                                                                                                                                                                  
  #004: H5Gint.c line 289 in H5G__open_name(): not a group                                                                                                                                    
    major: Symbol table                                                                                                                                                                       
    minor: Inappropriate type                                                                                                                                                                 
HDF5-DIAG: Error detected in HDF5 (1.12.0) thread 0:                                                                                                                                          
  #000: H5I.c line 2231 in H5Iget_name(): invalid identifier                                                                                                                                  
    major: Object atom                                                                                                                                                                        
    minor: Inappropriate type                                                                                                                                                                 
  #001: H5VLint.c line 1696 in H5VL_vol_object(): invalid identifier type to function                                                                                                         
    major: Invalid arguments to routine                                                                                                                                                       
    minor: Inappropriate type                                                                                                                                                                 
HDF5-DIAG: Error detected in HDF5 (1.12.0) thread 0:                                                                                                                                          
  #000: H5A.c line 541 in H5Aopen_by_name(): invalid location identifier                                                                                                                      
    major: Invalid arguments to routine       

I compile the program with g++ -std=c++17 and uploaded the used .mat-file on Google Drive. Loading the file in Octave works fine, therefore I don't think it is corrupted. Do you have any tips how I can deal with this issue?

SteScheller commented 4 years ago

The problem seems to be fixed in the current HEAD (596cb3ce71038958812bd6cf9b141f12ce155ac6).

SteScheller commented 4 years ago

Forgot to add that the problem can also be reproduced with v1.5.17.