From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9573A441F5 for ; Fri, 2 Sep 2022 07:04:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 921EC68B9D9; Fri, 2 Sep 2022 10:04:27 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 917D968B889 for ; Fri, 2 Sep 2022 10:04:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D7243240D0E for ; Fri, 2 Sep 2022 09:04:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LmKXffLBjQV0 for ; Fri, 2 Sep 2022 09:04:19 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 4DE4F240D03 for ; Fri, 2 Sep 2022 09:04:19 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id 784781601B2; Fri, 2 Sep 2022 09:04:19 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: References: Mail-Followup-To: FFmpeg development discussions and patches Date: Fri, 02 Sep 2022 09:04:19 +0200 Message-ID: <166210225946.3205.13102915136711192823@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH]lavfi/rotate: Fix undefined behaviour X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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. Also, shouldn't the same change be done also to interpolate_bilinear8? -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".