matio icon indicating copy to clipboard operation
matio copied to clipboard

Mat_VarReadNextInfo requires a large chunk on a 32KB file

Open frokaikan opened this issue 3 years ago • 2 comments

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?

frokaikan avatar May 05 '22 07:05 frokaikan

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.

tbeu avatar May 05 '22 12:05 tbeu

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.

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...

frokaikan avatar May 05 '22 13:05 frokaikan

Addressed by https://github.com/tbeu/matio/commit/0adfda6e129c2cedcae89a95918792e62fcd9bbd.

tbeu avatar Oct 26 '23 20:10 tbeu