-
-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
There is another thing I discovered with corrupted files.
matvar->data = calloc(nelems_x_nfields, matvar->data_size);
code like this may try to allocate enormous amount of memory. And I have an corrupted files which causes just this.
I thought to quickly fix it by adding the file size in mat_t struct and change all the allocations to check it. But since the file or some variable can be compressed it's hard to say what's the max size. Of course it's possible to use a multiplier to find approximate max of the max, but still it's sort of ugly.
Another idea would be to introduce a sort of compile-time constant which will be checked on every allocation, but probably this option is even worse.
more complex solution would be
- set limit on maximal size of values which can be returned by Matio API and processed without Matio aid. For example max size of a string.
- for everything else allocate memory in chunks and reallocate when necessary and/or design a multi-chunk structure and iterators over it. Maybe it's even better while iterating to handle just a current chunk, releasing the previous one.
- track total amount of allocated/de-allocated memory to have an impression how much more it's still reasonable to allocate. But this is only useful if we can somehow know in advance the max amount of memory available for the parent container.
Metadata
Metadata
Assignees
Labels
No labels