mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
alsa: guard against some invalid values
Avoid division by 0 and other strange things when invalid values are detected. Fixes #2953
This commit is contained in:
parent
68d9c33078
commit
32a7c85c84
1 changed files with 22 additions and 0 deletions
|
|
@ -1519,6 +1519,11 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
|||
fmt->info.raw.rate = rrate;
|
||||
match = false;
|
||||
}
|
||||
if (rchannels == 0 || rrate == 0) {
|
||||
spa_log_error(state->log, "%s: invalid channels:%d or rate:%d",
|
||||
state->props.device, rchannels, rrate);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
state->format = rformat;
|
||||
state->channels = rchannels;
|
||||
|
|
@ -1563,6 +1568,11 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
|||
|
||||
CHECK(snd_pcm_hw_params_set_period_size_near(hndl, params, &period_size, &dir), "set_period_size_near");
|
||||
|
||||
if (period_size == 0) {
|
||||
spa_log_error(state->log, "%s: invalid period_size 0 (driver error?)", state->props.device);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
state->period_frames = period_size;
|
||||
|
||||
if (state->default_period_num != 0) {
|
||||
|
|
@ -1578,6 +1588,10 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
|||
CHECK(snd_pcm_hw_params_set_buffer_size_near(hndl, params, &state->buffer_frames), "set_buffer_size_near");
|
||||
periods = state->buffer_frames / period_size;
|
||||
}
|
||||
if (state->buffer_frames == 0) {
|
||||
spa_log_error(state->log, "%s: invalid buffer_frames 0 (driver error?)", state->props.device);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
state->headroom = state->default_headroom;
|
||||
if (is_batch)
|
||||
|
|
@ -2542,6 +2556,14 @@ int spa_alsa_start(struct state *state)
|
|||
state->duration = 1024;
|
||||
state->rate_denom = state->rate;
|
||||
}
|
||||
if (state->rate_denom == 0) {
|
||||
spa_log_error(state->log, "%s: unset rate_denom", state->props.device);
|
||||
return -EIO;
|
||||
}
|
||||
if (state->duration == 0) {
|
||||
spa_log_error(state->log, "%s: unset duration", state->props.device);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
state->following = is_following(state);
|
||||
setup_matching(state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue