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

@ -303,11 +303,10 @@ static int port_set_format(void *object,
Uint32 sdl_format;
void *dest;
d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
if (format == NULL) {
spa_zero(d->format);
SDL_DestroyTexture(d->texture);
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
d->texture = NULL;
} else {
spa_debug_format(0, NULL, format);
@ -316,6 +315,9 @@ static int port_set_format(void *object,
sdl_format = id_to_sdl_format(d->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN)
return -EINVAL;
if (d->format.size.width == 0 ||
d->format.size.height == 0)
return -EINVAL;
d->texture = SDL_CreateTexture(d->renderer,
sdl_format,
@ -325,9 +327,16 @@ static int port_set_format(void *object,
SDL_LockTexture(d->texture, NULL, &dest, &d->stride);
SDL_UnlockTexture(d->texture);
}
d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
if (format) {
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
} else {
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
}
spa_node_emit_port_info(&d->hooks, direction, port_id, &d->info);
d->info.change_mask = 0;

View file

@ -275,26 +275,31 @@ static int port_set_format(void *object,
{
struct data *d = object;
d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
if (format == NULL) {
d->format.format = 0;
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
spa_node_emit_port_info(&d->hooks, SPA_DIRECTION_OUTPUT, 0, &d->info);
return 0;
spa_zero(d->format);
} else {
spa_debug_format(0, NULL, format);
if (spa_format_audio_raw_parse(format, &d->format) < 0)
return -EINVAL;
if (d->format.format != SPA_AUDIO_FORMAT_S16 &&
d->format.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
if (d->format.rate == 0 ||
d->format.channels == 0 ||
d->format.channels > SPA_AUDIO_MAX_CHANNELS)
return -EINVAL;
}
spa_debug_format(0, NULL, format);
if (spa_format_audio_raw_parse(format, &d->format) < 0)
return -EINVAL;
if (d->format.format != SPA_AUDIO_FORMAT_S16 &&
d->format.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
if (format) {
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
} else {
d->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
d->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
}
spa_node_emit_port_info(&d->hooks, SPA_DIRECTION_OUTPUT, 0, &d->info);
return 0;

View file

@ -207,28 +207,39 @@ static int port_set_format(void *object, enum spa_direction direction, uint32_t
Uint32 sdl_format;
void *dest;
if (format == NULL)
return 0;
if (format == NULL) {
spa_zero(d->format);
SDL_DestroyTexture(d->texture);
d->texture = NULL;
} else {
spa_debug_format(0, NULL, format);
spa_debug_format(0, NULL, format);
spa_format_video_raw_parse(format, &d->format);
spa_format_video_raw_parse(format, &d->format);
sdl_format = id_to_sdl_format(d->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN)
return -EINVAL;
if (d->format.size.width == 0 ||
d->format.size.height == 0)
return -EINVAL;
sdl_format = id_to_sdl_format(d->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN)
return -EINVAL;
d->texture = SDL_CreateTexture(d->renderer,
sdl_format,
SDL_TEXTUREACCESS_STREAMING,
d->format.size.width,
d->format.size.height);
SDL_LockTexture(d->texture, NULL, &dest, &d->stride);
SDL_UnlockTexture(d->texture);
d->texture = SDL_CreateTexture(d->renderer,
sdl_format,
SDL_TEXTUREACCESS_STREAMING,
d->format.size.width,
d->format.size.height);
SDL_LockTexture(d->texture, NULL, &dest, &d->stride);
SDL_UnlockTexture(d->texture);
}
d->info.change_mask = SPA_PORT_CHANGE_MASK_PARAMS;
d->params[1] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
d->params[2] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
if (format) {
d->params[1] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
d->params[2] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
} else {
d->params[1] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
d->params[2] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
}
spa_node_emit_port_info(&d->hooks, SPA_DIRECTION_INPUT, 0, &d->info);
return 0;

View file

@ -340,6 +340,10 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
pw_stream_set_error(stream, -EINVAL, "unknown pixel format");
return;
}
if (data->size.width == 0 || data->size.height == 0) {
pw_stream_set_error(stream, -EINVAL, "invalid size");
return;
}
data->texture = SDL_CreateTexture(data->renderer,
sdl_format,

View file

@ -388,6 +388,10 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
pw_stream_set_error(stream, -EINVAL, "unknown pixel format");
return;
}
if (data->size.width == 0 || data->size.height == 0) {
pw_stream_set_error(stream, -EINVAL, "invalid size");
return;
}
data->texture = SDL_CreateTexture(data->renderer,
sdl_format,

View file

@ -233,6 +233,10 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
pw_stream_set_error(stream, -EINVAL, "unknown pixel format");
return;
}
if (data->size.width == 0 || data->size.height == 0) {
pw_stream_set_error(stream, -EINVAL, "invalid size");
return;
}
data->texture = SDL_CreateTexture(data->renderer,
sdl_format,

View file

@ -336,6 +336,10 @@ on_stream_param_changed(void *_data, uint32_t id, const struct spa_pod *param)
pw_stream_set_error(stream, -EINVAL, "unknown pixel format");
return;
}
if (data->size.width == 0 || data->size.height == 0) {
pw_stream_set_error(stream, -EINVAL, "invalid size");
return;
}
data->texture = SDL_CreateTexture(data->renderer,
sdl_format,

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);