spa: handle empty values better

Make sure the properties are not empty before trying to access them.
This commit is contained in:
Wim Taymans 2024-04-10 11:08:40 +02:00
parent b5284791fc
commit b72ead1dea
3 changed files with 11 additions and 4 deletions

View file

@ -729,7 +729,7 @@ handle_id_prop (const struct spa_pod_prop *prop, const char *key, id_to_string_f
uint32_t i, n_items, choice;
val = spa_pod_get_values(&prop->value, &n_items, &choice);
if (val->type != SPA_TYPE_Id)
if (val->type != SPA_TYPE_Id || n_items == 0)
return;
id = SPA_POD_BODY(val);
@ -770,7 +770,7 @@ handle_int_prop (const struct spa_pod_prop *prop, const char *key, GstCaps *res)
uint32_t i, n_items, choice;
val = spa_pod_get_values(&prop->value, &n_items, &choice);
if (val->type != SPA_TYPE_Int)
if (val->type != SPA_TYPE_Int || n_items == 0)
return;
ints = SPA_POD_BODY(val);
@ -814,7 +814,7 @@ handle_rect_prop (const struct spa_pod_prop *prop, const char *width, const char
uint32_t i, n_items, choice;
val = spa_pod_get_values(&prop->value, &n_items, &choice);
if (val->type != SPA_TYPE_Rectangle)
if (val->type != SPA_TYPE_Rectangle || n_items == 0)
return;
rect = SPA_POD_BODY(val);
@ -867,7 +867,7 @@ handle_fraction_prop (const struct spa_pod_prop *prop, const char *key, GstCaps
uint32_t i, n_items, choice;
val = spa_pod_get_values(&prop->value, &n_items, &choice);
if (val->type != SPA_TYPE_Fraction)
if (val->type != SPA_TYPE_Fraction || n_items == 0)
return;
fract = SPA_POD_BODY(val);

View file

@ -687,6 +687,9 @@ static int add_int(struct format_info *info, const char *k, struct spa_pod *para
if (val->type != SPA_TYPE_Int)
return -ENOTSUP;
if (n_values == 0)
return -ENOENT;
values = SPA_POD_BODY(val);
switch (choice) {

View file

@ -1271,6 +1271,10 @@ static int node_event_param(void *object, int seq,
}
pod = spa_pod_get_values(type, &n_vals, &choice);
if (n_vals == 0) {
free(c);
return -EINVAL;
}
c->type = SPA_POD_TYPE(pod);
if (spa_pod_is_float(pod))