-
Notifications
You must be signed in to change notification settings - Fork 7
GSL::Vector::View usage is not safe, crashes Ruby #21
Comments
Thanks, I'll look into it. |
To correct myself if it is not impossible to implement views, but hard due to some parts are stored on the stack. They can be moved to heap, but this is not trivial. |
Hi Balint, I'm sorry, but I have to retract my earlier statement. At the moment, I don't have time to work on this library. I only created this fork to add support for newer Ruby and GSL versions and I'm not familiar with the inner workings of this code or GSL. I can give you commit access if you want and assist you in any way I can. Cheers, |
Hi Jens, |
Sure, I totally understand. I'm no longer working on this library, so I leave it to the new maintainer(s) to decide what to do about this issue. |
To help people using ruby-gsl in the meantime if you keep the vector in scope in does not get GC-ed and the program works properly.
|
Hi,
From https://www.gnu.org/software/gsl/manual/html_node/Vector-views.html :
A vector view is a temporary object, stored on the stack, which can be used to operate on a subset of vector elements. Vector views can be defined for both constant and non-constant vectors, using separate types that preserve constness. A vector view has the type gsl_vector_view and a constant vector view has the type gsl_vector_const_view. In both cases the elements of the view can be accessed as a gsl_vector using the vector component of the view object. A pointer to a vector of type gsl_vector * or const gsl_vector * can be obtained by taking the address of this component with the & operator.
When using this pointer it is important to ensure that the view itself remains in scope—the simplest way to do so is by always writing the pointer as &view.vector, and never storing this value in another variable.
The following simple test demonstrates the problem:
Result:
I think rb-gsl should not expose GSL views because it seems to be impossible to implement it properly.
The text was updated successfully, but these errors were encountered: