PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

ToNpyDims: Shared reference is casted to mutable pointer that might be mutated #343

Closed terrorfisch closed 2 years ago

terrorfisch commented 2 years ago

If I understand this numpy code correctly the memory location passed via PyArray_Dims is mutated if a wildcard dimension i.e. -1 is present.

This means that reshape and resize calls via ToNpyDims results in UB in all invocations with a -1 since the ptr is casted from a shared slice reference.

terrorfisch commented 2 years ago

Should be a simple fix by using slice_mut

davidhewitt commented 2 years ago

Fixed in #344