diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 9130f6f4abdee550a4e3af1dae058122fa8061d1..bd4d818d6bba35a433d89ead3d7abeb54cdca80c 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -177,6 +177,11 @@ static int config_output(AVFilterLink *outlink)
 
         av_rdft_end(s->rdft);
         s->rdft = av_rdft_init(rdft_bits, DFT_R2C);
+        if (!s->rdft) {
+            av_log(ctx, AV_LOG_ERROR, "Unable to create RDFT context. "
+                   "The window size might be too high.\n");
+            return AVERROR(EINVAL);
+        }
         s->rdft_bits = rdft_bits;
 
         /* RDFT buffers: x2 for each (display) channel buffer.