Add some more format checks

The format parse functions don't really check if the parsed values
make any sense so we need to to this ourselves.
This commit is contained in:
Wim Taymans 2022-11-03 13:10:32 +01:00
parent c30d743198
commit 74447acedb
24 changed files with 182 additions and 59 deletions

View file

@ -1011,14 +1011,15 @@ static void param_changed(void *data, uint32_t id, const struct spa_pod *param)
} else {
struct spa_audio_info_raw info;
spa_zero(info);
spa_format_audio_raw_parse(param, &info);
impl->rate = info.rate;
res = graph_instantiate(graph);
if (res < 0) {
pw_stream_set_error(impl->capture, res,
"can't start graph: %s",
spa_strerror(res));
if ((res = spa_format_audio_raw_parse(param, &info)) < 0)
goto error;
if (info.rate == 0) {
res = -EINVAL;
goto error;
}
impl->rate = info.rate;
if ((res = graph_instantiate(graph)) < 0)
goto error;
}
break;
case SPA_PARAM_Props:
@ -1029,6 +1030,11 @@ static void param_changed(void *data, uint32_t id, const struct spa_pod *param)
param_latency_changed(impl, param);
break;
}
return;
error:
pw_stream_set_error(impl->capture, res, "can't start graph: %s",
spa_strerror(res));
}
static const struct pw_stream_events in_stream_events = {

View file

@ -375,6 +375,10 @@ static void capture_param_changed(void *data, uint32_t id, const struct spa_pod
return;
if (spa_format_audio_raw_parse(param, &info) < 0)
return;
if (info.rate == 0 ||
info.channels == 0 ||
info.channels > SPA_AUDIO_MAX_CHANNELS)
return;
impl->capture_info = info;
recalculate_buffer(impl);