ralna / spral

Sparse Parallel Robust Algorithms Library
https://ralna.github.io/spral/
Other
102 stars 27 forks source link

Insufficient memory allocation in SSIDS C interface #198

Closed chrhansk closed 1 month ago

chrhansk commented 1 month ago

I am currently working on a python interface to spral including SSIDS. To this end, I am using the C bindings to the Fortran code of SSIDS located in interfaces/C/ssids.f90. I would prefer to use C indexing as it is the indexing underlying pythons numpy. However, my code crashes whenever I try to pass a matrix to spral_ssids_analyse with options.array_base = 0.

I think there is an error in the memory allocation that is causing the problem. Specifically, a segfault occurs at

https://github.com/ralna/spral/blob/master/interfaces/C/ssids.f90#L462

where a newly allocated array is initialized. The problem is that the allocation here

https://github.com/ralna/spral/blob/master/interfaces/C/ssids.f90#L461

reserves n + 1 entries rather than the required #nnz = fptr(fakeep%n+1)-1 to hold the array, causing an overflow. This seems to be done correctly in other places, for example here:

https://github.com/ralna/spral/blob/master/interfaces/C/ssids.f90#L184

Could you look into and fix this issue?

jfowkes commented 1 month ago

Thanks for reporting, this is clearly a stupid bug. I will create a PR to fix shortly.