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 61af61a4b3
commit c534acac46
3 changed files with 13 additions and 6 deletions

View file

@ -842,7 +842,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);
@ -887,7 +887,7 @@ handle_dmabuf_prop (const struct spa_pod_prop *prop,
uint64_t *mods;
val = spa_pod_get_values (&prop->value, &n_fmts, &choice);
if (val->type != SPA_TYPE_Id)
if (val->type != SPA_TYPE_Id || n_fmts == 0)
return;
if (choice != SPA_CHOICE_None && choice != SPA_CHOICE_Enum)
return;
@ -899,7 +899,7 @@ handle_dmabuf_prop (const struct spa_pod_prop *prop,
}
pod_modifier = spa_pod_get_values (&prop_modifier->value, &n_mods, &choice);
if (pod_modifier->type != SPA_TYPE_Long)
if (pod_modifier->type != SPA_TYPE_Long || n_mods == 0)
return;
if (choice != SPA_CHOICE_None && choice != SPA_CHOICE_Enum)
return;
@ -991,7 +991,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);
@ -1035,7 +1035,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);
@ -1088,7 +1088,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

@ -1285,6 +1285,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))