Commit 52c959a2 authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_aiir: do not crash with invalid options

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 89b84cb1
...@@ -127,6 +127,9 @@ static void count_coefficients(char *item_str, int *nb_items) ...@@ -127,6 +127,9 @@ static void count_coefficients(char *item_str, int *nb_items)
{ {
char *p; char *p;
if (!item_str)
return;
*nb_items = 1; *nb_items = 1;
for (p = item_str; *p && *p != '|'; p++) { for (p = item_str; *p && *p != '|'; p++) {
if (*p == ' ') if (*p == ' ')
...@@ -170,10 +173,14 @@ static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, ...@@ -170,10 +173,14 @@ static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str,
if (!(arg = av_strtok(p, "|", &saveptr))) if (!(arg = av_strtok(p, "|", &saveptr)))
arg = prev_arg; arg = prev_arg;
p = NULL; if (!arg)
return AVERROR(EINVAL);
count_coefficients(arg, &nb[i]); count_coefficients(arg, &nb[i]);
cache[i] = av_calloc(nb[i], sizeof(cache[i]));
c[i] = av_calloc(nb[i], sizeof(c[i])); p = NULL;
cache[i] = av_calloc(nb[i] + 1, sizeof(double));
c[i] = av_calloc(nb[i], sizeof(double));
if (!c[i] || !cache[i]) if (!c[i] || !cache[i])
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -263,6 +270,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -263,6 +270,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
return ff_filter_frame(outlink, out); return ff_filter_frame(outlink, out);
} }
static av_cold int init(AVFilterContext *ctx)
{
AudioIIRContext *s = ctx->priv;
if (!s->a_str || !s->b_str) {
av_log(ctx, AV_LOG_ERROR, "Valid coefficients are mandatory.\n");
return AVERROR(EINVAL);
}
return 0;
}
static av_cold void uninit(AVFilterContext *ctx) static av_cold void uninit(AVFilterContext *ctx)
{ {
AudioIIRContext *s = ctx->priv; AudioIIRContext *s = ctx->priv;
...@@ -326,6 +345,7 @@ AVFilter ff_af_aiir = { ...@@ -326,6 +345,7 @@ AVFilter ff_af_aiir = {
.name = "aiir", .name = "aiir",
.description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."), .description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."),
.priv_size = sizeof(AudioIIRContext), .priv_size = sizeof(AudioIIRContext),
.init = init,
.uninit = uninit, .uninit = uninit,
.query_formats = query_formats, .query_formats = query_formats,
.inputs = inputs, .inputs = inputs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment