[FFmpeg-cvslog] avfilter/vf_palettegen: add protection against potential divide by zero

Yiyuan GUO git at videolan.org
Mon Mar 14 18:53:33 EET 2022


ffmpeg | branch: master | Yiyuan GUO <yguoaz at gmail.com> | Sat May 15 13:54:35 2021 +0800| [2201c91fbf672447aa2063bd752d821466b8f11b] | committer: Paul B Mahol

avfilter/vf_palettegen: add protection against potential divide by zero

In libavfilter/vf_palettegen.c, the function get_avg_color requires
that box->len greater than zero to avoid dividing by zero. However,
the call sequence filter_frame -> get_palette_frame -> get_avg_color
may not satisfy this precondition. Fixes #9222.

Signed-off-by: Yiyuan GUO <yguoaz at gmail.com>

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

 libavfilter/vf_palettegen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c
index 4f53aa1aad..27f74fd147 100644
--- a/libavfilter/vf_palettegen.c
+++ b/libavfilter/vf_palettegen.c
@@ -528,7 +528,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     if (s->stats_mode == STATS_MODE_DIFF_FRAMES) {
         av_frame_free(&s->prev_frame);
         s->prev_frame = in;
-    } else if (s->stats_mode == STATS_MODE_SINGLE_FRAMES) {
+    } else if (s->stats_mode == STATS_MODE_SINGLE_FRAMES && s->nb_refs > 0) {
         AVFrame *out;
         int i;
 



More information about the ffmpeg-cvslog mailing list