Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out-of-bounds access in CVODE when vector of absolute tolerances has the wrong shape #108

Open
astoeriko opened this issue Jan 3, 2022 · 1 comment

Comments

@astoeriko
Copy link

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.

@tbrk
Copy link

tbrk commented Jan 17, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants