Seeking SamplesBuffer to position 0 panics

Open Beginner friendly
#923 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust

Research direction

The panic is in src/buffer.rs around line 116, inside the seek path of SamplesBuffer, where new_pos - curr_channel underflows when the target position is 0. Start by reading how try_seek computes new_pos and curr_channel, then reproduce with the snippet from the issue. Done means seeking to Duration::from_secs(0) no longer panics and lands on the first sample of the correct channel, with a test covering that case.

Written by the indexing model from the issue text.

Description

bug

When seeking rodio::buffer::SamplesBuffer to Duration::from_secs(0), a panic occurs:

use rodio::nz;
use rodio::buffer::SamplesBuffer;
use std::time::Duration;
let mut buffer = SamplesBuffer::new(nz!(2), nz!(44100), vec![0.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
buffer.next();
buffer.try_seek(Duration::from_secs(0));

Error message:

[windows] thread 'main' (23364) panicked at C:\Users\User\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rodio-0.22.2\src\buffer.rs:116:23:
[windows] attempt to subtract with overflow

The line where it happens:

// make sure the next sample is for the right channel
let new_pos = new_pos.next_multiple_of(self.channels().get() as usize);
let new_pos = new_pos - curr_channel;

It looks like curr_channel is being subtracted from new_pos, which in this case is equal to 0, causing an underflow.

Dominant language
Rust
Stars
2.5k
Forks
338
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RustAudio/rodio

All issues in RustAudio/rodio

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.