casadi / casadi

CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.
http://casadi.org
GNU Lesser General Public License v3.0
1.71k stars 379 forks source link

Runtime errors because of fixed length vectors in casadi_cvx.hpp #3169

Open victorfors opened 1 year ago

victorfors commented 1 year ago

There are some stack-allocated vectors in casadi_cvx.hpp that limit the maximum size the input matrix can have. If your matrix is larger you run into undefined behavior, stack smashing or segmentation fault errors.

T1 beta[100] in the casadi_cvx function limits the input matrix to I believe 102x102. T1 pp[1000] in casadi_cvx_tri limits the input matrix to 1000x1000.

victorfors commented 1 year ago

I think it makes most sense to create them at the same places as other work vectors used in these functions. Let me know if you think otherwise. I will make a PR with a suggested fix.

victorfors commented 1 year ago

I have made an implementation of this but it seems to break the backwards compatibility (test below). I assume any commits that updates the size of the work vector would do so.

https://github.com/casadi/casadi/blob/main/test/python/serialize.py