sundials
sundials copied to clipboard
Out-of-bounds access in CVODE when vector of absolute tolerances has the wrong shape
CVodeSVtolerances
allows to specify state-specific absolute tolerances with a vector. However, it does not check that the vector passed to the function actually has the correct length. When the vector has too few entries, it will simply access memory that does not belong to the vector.
This leads to really strange behavior that is very hard to debug because the solver sometimes fails to converge and sometimes does not with the same code (depending on what numbers coincidentally are in the memory section following the vector).
Maybe aborting in NVector
-operations when shapes mismatch would also make it easier to debug issues like this.
Tested with SUNDIALS version 5.8.0, but as far as I see the problem should still exist in 6.0.0.
One way of implementing this enhancement would be to add an int nvcheck(N_Vector)
nvector operation to check the id and size of the target and an argument. It would, of course, have to be called by each function that takes an nvector argument, which is tedious, especially for arrays of nvectors. We do something like this in the OCaml interface to avoid memory access errors.