jeenalee / tv1d

Total variation denoising algorithms for 1D data.
https://docs.rs/tv1d
MIT License
5 stars 2 forks source link

`condat` can subtract or add with overflow #4

Open gamma-delta opened 4 years ago

gamma-delta commented 4 years ago

https://github.com/jeenalee/tv1d/blob/master/src/lib.rs#L320

Sample code: (I have not actually tested this code but it seems like it should cause the overflow)

let my_vec: Vec<i8> = vec![127];
tv1d::condat(my_vec, 10);

Due to the add and subtract on those two lines of code not being checked, an overflow may occur. This happened to me when I was using tv1d to denoise some audio.

gamma-delta commented 4 years ago

According to the backtrace, the panic is actually called by https://github.com/jeenalee/tv1d/blob/master/src/lib.rs#L363. I think this must be due to an automatic conversion to a type without as much fidelity as whatever is used internally.