Skip to content

Conversation

@cbs228
Copy link
Owner

@cbs228 cbs228 commented Aug 30, 2025

SliceRingBuffer is unsound and has multiple security advisories 1 2. There has been no apparent progress on fixes since May 2025 3. The crate's large volume of interdependent unsafe blocks will likely make it very tricky to maintain.

SliceRingBuffer backs the FIR filter Window. The slice coercion is used to align the back of the Window (with the most recent samples) with the FIR filter taps. We don't actually need a slice for this: we can get by with a DoubleEndedIterator instead.

  • Make Window convertible to an iterator of numbers, via IntoIterator. Replace all uses of slices with iterators.

  • Store FIR FilterCoeff taps in "proper" order, instead of reversed. Since we use iterators instead of slices, reverse-order is no longer convenient.

  • Replace SliceRingBuffer with std::collections::VecDeque.

Testing indicates that VecDeque may be up to twice as fast as the previous implementation.

Closes #53

cbs228 added 3 commits August 30, 2025 16:53
`SliceRingBuffer` is unsound and has multiple security
advisories [1] [2]. There has been no apparent progress on fixes
since May 2025 [3]. The crate's large volume of interdependent
`unsafe` blocks will likely make it very tricky to maintain.

While a memory-mapped deque is a very cool idea, it is time to
move on for now.

Let's replace `SliceRingBuffer` with a more traditional
double-ended queue.

These queues don't covert to slice, but we don't really *need* a
slice. At present, slice is mostly used to align the end of
`Window` (with the most recent samples) to the filter taps. We
can do that just as easily with a `DoubleEndedIterator`.

* Make `Window` convertible to an iterator of numbers, via
  `IntoIterator`. Replace all uses of slices with iterators.

* Remove slice conversions and accessors from Window. They're
  still technically accessible via `inner()`, but nothing uses
  them.

[1]: https://rustsec.org/advisories/RUSTSEC-2025-0044

[2]: https://rustsec.org/advisories/RUSTSEC-2020-0158

[3]: LiquidityC/slice_ring_buffer#12
Previously, `FilterCoeff` were stored in reverse order, with
feedforward lag 0 stored *last*. This was convenient when `Window`
coerced to slice. Now that we iterate over `Window` in reverse
order, reversing the filter taps does not serve us. It is also
confusing: the taps are in "normal" order in
`FilterCoeff::from_slice()`, but later reads via `as_slice()`
show them reversed. Ick.

Put filter taps in their proper order.
Replace `SliceRingBuffer` with a standard `VecDeque` in our FIR
filter `Window` implementation. The crate dependency is dropped.
@cbs228 cbs228 force-pushed the bugfix/eliminate_slice_deque branch from 5549562 to 3d40e65 Compare August 30, 2025 23:05
@cbs228 cbs228 merged commit 7547bc6 into develop Aug 30, 2025
10 checks passed
@cbs228 cbs228 deleted the bugfix/eliminate_slice_deque branch August 30, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slice Ring Buffer and Slice Deque contains four unique double-free vulnerabilities triggered through safe APIs

2 participants