avfilter/vf_paletteuse: fix some integer overflows

This commit is contained in:
Paul B Mahol 2021-08-18 23:31:03 +02:00
parent 835eb0a556
commit 6d09de90d1
1 changed files with 6 additions and 6 deletions

View File

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