count_items() counts every comma delimiter while av_strtok() skips empty
fields, so an attacks argument such as "1,,2,3" has more nominal items
than tokens. config_output() then passes the NULL token from the fourth
av_strtok() to sscanf(), which dereferences it and crashes.

Check both tokens and conversion results, returning AVERROR(EINVAL) with
a diagnostic instead.

Signed-off-by: Mohammed Mustafa <[email protected]>
---
 libavfilter/af_mcompand.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavfilter/af_mcompand.c b/libavfilter/af_mcompand.c
index 855d893550..a70a3e0df4 100644
--- a/libavfilter/af_mcompand.c
+++ b/libavfilter/af_mcompand.c
@@ -361,9 +361,15 @@ static int config_output(AVFilterLink *outlink)
             char *tstr3 = av_strtok(p3, ",", &saveptr3);

             p3 = NULL;
-            sscanf(tstr3, "%lf", &s->bands[i].attack_rate[k]);
+            if (!tstr3 || sscanf(tstr3, "%lf",
&s->bands[i].attack_rate[k]) != 1) {
+                av_log(ctx, AV_LOG_ERROR, "invalid attacks rate\n");
+                return AVERROR(EINVAL);
+            }
             tstr3 = av_strtok(p3, ",", &saveptr3);
-            sscanf(tstr3, "%lf", &s->bands[i].decay_rate[k]);
+            if (!tstr3 || sscanf(tstr3, "%lf",
&s->bands[i].decay_rate[k]) != 1) {
+                av_log(ctx, AV_LOG_ERROR, "invalid decays rate\n");
+                return AVERROR(EINVAL);
+            }

             if (s->bands[i].attack_rate[k] > 1.0 / outlink->sample_rate) {
                 s->bands[i].attack_rate[k] = 1.0 - exp(-1.0 /
(outlink->sample_rate * s->bands[i].attack_rate[k]));
-- 
2.56.1
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to