diff --git a/libavfilter/af_stereotools.c b/libavfilter/af_stereotools.c
index 3c796f5b15e7ddc97e35b4819acc831db78b164b..00a0dde2815b060c3210c016d69f3046aecad2c1 100644
--- a/libavfilter/af_stereotools.c
+++ b/libavfilter/af_stereotools.c
@@ -110,6 +110,10 @@ static int config_input(AVFilterLink *inlink)
     StereoToolsContext *s = ctx->priv;
 
     s->length = 2 * inlink->sample_rate * 0.05;
+    if (s->length <= 1 && s->length & 1) {
+        av_log(ctx, AV_LOG_ERROR, "sample rate is too small\n");
+        return AVERROR(EINVAL);
+    }
     s->buffer = av_calloc(s->length, sizeof(*s->buffer));
     if (!s->buffer)
         return AVERROR(ENOMEM);