cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Panics on overflows with more than 1 channel

Open JDuchniewicz opened this issue 5 years ago • 4 comments

I created a cpal::StreamConfig for an output device for ALSA backend with following parameters: channels: 2 (or more, if 5 it crashes even earlier), sample_rate: 44100 buffer_size: Default

It panics with on multiply overflow: thread '<unnamed>' panicked at 'attempt to multiply with overflow', /home/jduchniewicz/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.12.1/src/host/alsa/mod.rs:677:23

The offending lines are: let buffer_size = stream.sample_format.sample_size() * available_samples; or let available_samples = avail_frames * stream.conf.channels as usize; when I even further increase the number of channels.

From my own investigation it looks like ALSA suddenly provides too many samples from PCM stream. First two transfers from cpal are fine, the third one is gigantic and overflows. Maybe this is not related to cpal, but to ALSA. However, I doubt it.

JDuchniewicz avatar Sep 26 '20 14:09 JDuchniewicz

I had a similar issue:

thread '<unnamed>' panicked at 'attempt to multiply with overflow', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692:23

On Arch Linux, the fix for me was to install pulseaudio-alsa:

sudo pacman -S pulseaudio-alsa

delpozzo avatar Jan 29 '21 16:01 delpozzo

Also on Arch, pulseaudio-alsa was installed a long timke ago (and update), same issue:

thread '<unnamed>' panicked at 'attempt to multiply with overflow', /home/steven/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692:23

crides avatar Feb 19 '21 20:02 crides

I just added below as a work around

if avail_frames > 1024 * 1024 * 64 { 
    return Ok(PollDescriptorsFlow::Continue);
}  

open-trade avatar Aug 23 '21 04:08 open-trade

I just added below as a work around

if avail_frames > 1024 * 1024 * 64 { 
    return Ok(PollDescriptorsFlow::Continue);
}  

Where did you put that?

nck974 avatar Nov 04 '23 15:11 nck974