rogersce / cnpy

library to read/write .npy and .npz files in C/C++
MIT License
1.34k stars 301 forks source link

cnpy::npy_save not checking if file is open (leading to segmentation fault) #46

Open VladikNeVladik opened 5 years ago

VladikNeVladik commented 5 years ago

Somewhere in the cnpy::npy_save(...):

if (fp) {
    ...
}
else {
    fp = fopen(fname.c_str(),"wb");
    true_data_shape = shape;
}
...
fseek(fp,0,SEEK_SET); // It raises segmentation fault
adrian-bodenmann commented 1 year ago

Running into the same issue. Should check if fp is valit (not NULL), and if not valid gracefully abort or throw an exception. Not doing so causes fseek() to segmentation fault