[FFmpeg-cvslog] avfilter/avf_showspectrum: fix 2 possible crashes

Paul B Mahol git at videolan.org
Fri Jan 27 14:38:42 EET 2017


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Jan 27 13:37:00 2017 +0100| [836c8750b31329e71e5ac2a194523172875b77eb] | committer: Paul B Mahol

avfilter/avf_showspectrum: fix 2 possible crashes

Make sure no division by zero is done.
Make sure there are actually samples available.

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=836c8750b31329e71e5ac2a194523172875b77eb
---

 libavfilter/avf_showspectrum.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 8776668..09b5a2a 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -1022,17 +1022,19 @@ static int showspectrumpic_request_frame(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     ShowSpectrumContext *s = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
-    int ret;
+    int ret, samples;
 
     ret = ff_request_frame(inlink);
-    if (ret == AVERROR_EOF && s->outpicref) {
-        int samples = av_audio_fifo_size(s->fifo);
+    samples = av_audio_fifo_size(s->fifo);
+    if (ret == AVERROR_EOF && s->outpicref && samples > 0) {
         int consumed = 0;
         int y, x = 0, sz = s->orientation == VERTICAL ? s->w : s->h;
         int ch, spf, spb;
         AVFrame *fin;
 
         spf = s->win_size * (samples / ((s->win_size * sz) * ceil(samples / (float)(s->win_size * sz))));
+        spf = FFMAX(1, spf);
+
         spb = (samples / (spf * sz)) * spf;
 
         fin = ff_get_audio_buffer(inlink, s->win_size);



More information about the ffmpeg-cvslog mailing list