Fix reading dimensions from v5 MAT file
Fix reading dimensions from v5 MAT file

* Check read success
* Check allocation success
* Fix array index out of bounds (if rank > 16)
* Move code to separate function
* As reported  by https://sourceforge.net/p/matio/discussion/609376/thread/cb6d66ea/ and https://github.com/jcupitt/libvips/issues/1039

tbeu/matio,MaartenBent/matio,tbeu/matio,tbeu/matio,MaartenBent/matio,MaartenBent/matio,tbeu/matio,MaartenBent/matio