[FFmpeg-cvslog] avfilter/vf_paletteuse: fix some integer overflows

Paul B Mahol git at videolan.org
Thu Aug 19 10:48:40 EEST 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Wed Aug 18 23:31:03 2021 +0200| [6d09de90d1a1544e47c959de58189df30de9cda8] | committer: Paul B Mahol

avfilter/vf_paletteuse: fix some integer overflows

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

 libavfilter/vf_paletteuse.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index 1f1e36ba8e..4b2144c6f9 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -380,9 +380,9 @@ static av_always_inline int get_dst_color_err(PaletteUseContext *s,
     if (dstx < 0)
         return dstx;
     dstc = s->palette[dstx];
-    *er = r - (dstc >> 16 & 0xff);
-    *eg = g - (dstc >>  8 & 0xff);
-    *eb = b - (dstc       & 0xff);
+    *er = (int)r - (int)(dstc >> 16 & 0xff);
+    *eg = (int)g - (int)(dstc >>  8 & 0xff);
+    *eb = (int)b - (int)(dstc       & 0xff);
     return dstx;
 }
 
@@ -597,8 +597,8 @@ static int cmp_##name(const void *pa, const void *pb)   \
 {                                                       \
     const struct color *a = pa;                         \
     const struct color *b = pb;                         \
-    return   (a->value >> (8 * (3 - (pos))) & 0xff)     \
-           - (b->value >> (8 * (3 - (pos))) & 0xff);    \
+    return   (int)(a->value >> (8 * (3 - (pos))) & 0xff)     \
+           - (int)(b->value >> (8 * (3 - (pos))) & 0xff);    \
 }
 
 DECLARE_CMP_FUNC(a, 0)
@@ -704,7 +704,7 @@ static int colormap_insert(struct color_node *map,
     /* get the two boxes this node creates */
     box1 = box2 = *box;
     box1.max[component-1] = node->val[component];
-    box2.min[component-1] = node->val[component] + 1;
+    box2.min[component-1] = FFMIN(node->val[component] + 1, 255);
 
     node_left_id = colormap_insert(map, color_used, nb_used, palette, trans_thresh, &box1);
 



More information about the ffmpeg-cvslog mailing list