diff mbox series

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

Message ID 20210515055435.69717-1-yguoaz@gmail.com
State New
Headers show
Series [FFmpeg-devel] avfilter/vf_palettegen: add protection against potential divide by zero | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Yiyuan GUO May 15, 2021, 5:54 a.m. UTC
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. The bug is detailed in the bug
tracker:https://trac.ffmpeg.org/ticket/9222.

Signed-off-by: Yiyuan GUO <yguoaz@gmail.com>
---
 libavfilter/vf_palettegen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c
index ef8bc18..73ec3c7 100644
--- a/libavfilter/vf_palettegen.c
+++ b/libavfilter/vf_palettegen.c
@@ -489,7 +489,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) {
         AVFrame *out;
         int i;