Mat_VarReadNextInfo requires a large chunk on a 32KB file
Here is the program
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include "matio.h"
int main (int argc, char **argv) {
mat_t *ptr = Mat_Open(argv[1], 0);
auto *var = Mat_VarReadNextInfo(ptr);
Mat_VarFree(var);
Mat_Close(ptr);
}
And here is the file (zipped),
testfile.zip , which is a 32-KB file
Mat_VarReadNextInfo allocates 4278583297 bytes (about 4GB).
Maybe there can be a better implementation?
With logging enabled I get
Unexpected end-of-file: Read 32599 bytes, expected 4278583296 bytes
Could it be that you missed to write the MAT file completely.
With logging enabled I get
Unexpected end-of-file: Read 32599 bytes, expected 4278583296 bytesCould it be that you missed to write the MAT file completely.
Ah, I also got this message.
However, the message is printed AFTER the chunk has been allocated. I think the too-large chunk should not be even allocated.
Actually, I compile the program with AddressSanitizer and run it with ASAN_OPTIONS=max_allocation_size_mb=3000 , then ASAN reports the error...
Addressed by https://github.com/tbeu/matio/commit/0adfda6e129c2cedcae89a95918792e62fcd9bbd.