Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsafe precondition(s) violated: slice::get_unchecked_mut index not within slice #42

Open
yuvadm opened this issue May 30, 2024 · 5 comments

Comments

@yuvadm
Copy link

yuvadm commented May 30, 2024

next_frame() has some unsafe code that dumps core, not entirely sure why this happens, the stream should be valid mp3, but either way this shouldn't happen.

$ RUST_BACKTRACE=1 cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/foo`
thread 'main' panicked at library/core/src/panicking.rs:156:5:
unsafe precondition(s) violated: slice::get_unchecked_mut requires that the index is within the slice
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9
   3: core::panicking::panic_nounwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
   4: <usize as core::slice::index::SliceIndex<[T]>>::get_unchecked_mut::precondition_check
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/intrinsics.rs:2799:21
   5: <usize as core::slice::index::SliceIndex<[T]>>::get_unchecked_mut
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/slice/index.rs:252:9
   6: core::slice::<impl [T]>::get_unchecked_mut
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/slice/mod.rs:728:24
   7: slice_deque::SliceDeque<T>::extend_desugared
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slice-deque-0.3.0/src/lib.rs:1720:28
   8: <slice_deque::SliceDeque<T> as slice_deque::SpecExtend<T,I>>::spec_extend
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slice-deque-0.3.0/src/lib.rs:2614:9
   9: <slice_deque::SliceDeque<T> as slice_deque::SpecExtend<&T,I>>::spec_extend
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slice-deque-0.3.0/src/lib.rs:2702:9
  10: <slice_deque::SliceDeque<T> as core::iter::traits::collect::Extend<&T>>::extend
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slice-deque-0.3.0/src/lib.rs:2856:9
  11: minimp3::Decoder<R>::refill
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/minimp3-0.5.1/src/lib.rs:199:9
  12: minimp3::Decoder<R>::next_frame
             at /home/yuval/.cargo/registry/src/index.crates.io-6f17d22bba15001f/minimp3-0.5.1/src/lib.rs:177:22
  13: foo::mp3::Mp3StreamDecoder<R>::new
             at ./src/mp3.rs:32:29
  14: foo::main
             at ./src/main.rs:8:18
  15: core::ops::function::FnOnce::call_once
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
@Cerber-Ursi
Copy link

The error seems to be actually inside slice_deque implementation, judging from the backtrace. That crate seems to be unmaintained - gnzlbg/slice_deque#94, so maybe it should be replaced?

@AspadaX
Copy link

AspadaX commented Jul 24, 2024

I got the same issue.

@metasophiea
Copy link

metasophiea commented Jul 26, 2024

The error seems to be actually inside slice_deque implementation, judging from the backtrace. That crate seems to be unmaintained - gnzlbg/slice_deque#94, so maybe it should be replaced?

That issue thread has someone forking slice_deque and crating slice_ring_buffer. I tried replacing slice_deque with slice_ring_buffer but it seems to run into the same error

Another user noticed this in the slice_ring_buffer repo, and created a pull request addressing the issue back in May
LiquidityC/slice_ring_buffer#10

I've sent the owner of the slice_ring_buffer repo an email about merging and publishing that change

@metasophiea
Copy link

The owner of the slice_ring_buffer repo has performed the required merge and publish actions to update slice_ring_buffer, so I've now made a pull request on this repository to use slice_ring_buffer #43

@adierking
Copy link

Thanks for contacting the maintainer! 😃

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

No branches or pull requests

5 participants