Am Fr., 2. Sept. 2022 um 09:04 Uhr schrieb Anton Khirnov : > > Quoting Carl Eugen Hoyos (2022-09-01 21:28:08) > > Hi! > > > > Attached patch fixes ticket #9799. > > > > Please comment, Carl Eugen > > > > From 2cce687961c3b56a92d88184269bf9fa075ae297 Mon Sep 17 00:00:00 2001 > > From: Carl Eugen Hoyos > > Date: Thu, 1 Sep 2022 20:55:54 +0200 > > Subject: [PATCH] lavfi/rotate: Avoid undefined behaviour. > > > > Fixes the following integer overflows: > > libavfilter/vf_rotate.c:273:13: runtime error: signed integer overflow: 92951468 + 2058533568 cannot be represented in type 'int' > > libavfilter/vf_rotate.c:273:37: runtime error: signed integer overflow: 39684 * 54149 cannot be represented in type 'int' > > libavfilter/vf_rotate.c:272:13: runtime error: signed integer overflow: 247587320 + 1900985032 cannot be represented in type 'int' > > libavfilter/vf_rotate.c:272:37: runtime error: signed integer overflow: 42584 * 50430 cannot be represented in type 'int' > > libavfilter/vf_rotate.c:272:50: runtime error: signed integer overflow: 65083 * 52912 cannot be represented in type 'int' > > libavfilter/vf_rotate.c:273:50: runtime error: signed integer overflow: 65286 * 38044 cannot be represented in type 'int' > > > > Fixes ticket #9799, different output with different compilers. > > --- > > libavfilter/vf_rotate.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/libavfilter/vf_rotate.c b/libavfilter/vf_rotate.c > > index 4429e3d543..d319dfe3d9 100644 > > --- a/libavfilter/vf_rotate.c > > +++ b/libavfilter/vf_rotate.c > > @@ -269,8 +269,8 @@ static uint8_t *interpolate_bilinear16(uint8_t *dst_color, > > int s01 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y ]); > > int s10 = AV_RL16(&src[src_linestep * int_x + i + src_linesize * int_y1]); > > int s11 = AV_RL16(&src[src_linestep * int_x1 + i + src_linesize * int_y1]); > > - int s0 = (((1<<16) - frac_x)*s00 + frac_x*s01); > > - int s1 = (((1<<16) - frac_x)*s10 + frac_x*s11); > > + int64_t s0 = (((int64_t)(1<<16) - frac_x)*s00 + (int64_t)frac_x*s01); > > + int64_t s1 = (((int64_t)(1<<16) - frac_x)*s10 + (int64_t)frac_x*s11); > > Given that the same casts also appear in the AV_WL16 below, it seems > better to just change the types of frac_x/frac_y. Definitely, new patch attached. > Also, shouldn't the same change be done also to interpolate_bilinear8? I was unable to reproduce with 8-bit input. Thank you, Carl Eugen