From patchwork Fri Apr 26 03:08:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 48264 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1509:b0:1a9:af23:56c1 with SMTP id nq9csp112303pzb; Thu, 25 Apr 2024 20:09:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWW2ax8awuA2qV6sTHroQyz2GGY9O8skQMNssp0ekNP6lVlADT31ASwFrNtt2daOaGGtBsnJ5FtuxBhsVr8dprMnyaGxzMOcwji7w== X-Google-Smtp-Source: AGHT+IHaYn1LpbbZgxNNd9MvnSo3/fP5R9ZP0TbSUzExt27FM+N5u62bxJLsEhDn77q45CAWkbyI X-Received: by 2002:a17:906:2a96:b0:a55:b2e9:413a with SMTP id l22-20020a1709062a9600b00a55b2e9413amr692931eje.7.1714100954867; Thu, 25 Apr 2024 20:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714100954; cv=none; d=google.com; s=arc-20160816; b=BkwZf6DTgXOXjc/vYMrRsseR9vHW7SEFq4xpge7jk/Kee5yjJNC7rBxu8HzMhLYSXK 6PTp3DZhcA4fj2eVO3Asqo54Z8i7pj8sisxiQ9w5CngGPfOPD1PUX6zs/kIv1vJOVdqp gkhFeeWOTLD88f2aL/adLrkTZ8+nivkihz8qs9HbgbikK7KXNBgJA4Bl0N1WPIQTvMrg FfxQGi79GuxveWSJ+apmaCDppoEwQDQFx2iUSR2ER/xU2uIU7zbNcul2hVzy12VcXsS0 w/JnPwJR/dr4IJ5aJPmBC0IRbH/gLSodgMhQY4FElkjC4IfqtGfQrnV+sdrU26mCsiLC BGzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=9gwkEcn4Ho9F2044GfepGUb8iXrcgOzHda21vy2kclk=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=UIe55TG4ECZ30zL6+T8wSJqykmtWbr4vZGbHb0/v4MgjpHxLoQgOP3SFXhDgpil2nL lkDISYkCL6eWdL3HZ0cn/l7OmAMJe+XnVQvBou/A+UUePfaisjxLm5B07nC8yWfG/+SU bUHnVDrN0btAW8AJo8nX/htqQZDfc3zAaXl0gnp6Fd2rMoYTkZE5ZFnJf6kAHWvUwkke gCDbBDE0cIp17xrIsImz5UOW9WktVcoyg808cxiBzILST9tRkqXeHdYT5D3CpqK2Ev6V 2CJUG6nedSWoj3OxVEwH0qXrnd+Gb9rOHRKq+pb1MLYdPNAefejI6CIVEMe4RjEyqP9k 5oMw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=E5zNIT8L; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gs38-20020a1709072d2600b00a55abdb43a9si7562829ejc.371.2024.04.25.20.09.14; Thu, 25 Apr 2024 20:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=E5zNIT8L; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C063768D436; Fri, 26 Apr 2024 06:08:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A99B68D3C6 for ; Fri, 26 Apr 2024 06:08:43 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6A5B81BF206 for ; Fri, 26 Apr 2024 03:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1714100922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C74gUFu2Of9qmGI0USz7TsVNrpMl4KQOTxbUO3ILOTs=; b=E5zNIT8LJAmrC/VOMscM10Hu2MWQBRy3/W4dvywutrr8+sJDuL8B9ErM83GDQk6GvfhBOA WPtoI+zn+IHg9eja9cr0Rg4DXYu04Ydxep6FulyDeug5nmqesyu7811RVDGs3RDEp41pdl +TQuvdvqgpom4sfTyur7JiGGw5WV5HarkOiM+OddOUXJ+BBm2JRP+Nlp/rxZholM33xHru FhbPObKz73UNku0FF11zzF/g6QYEAUAhYXnaajjXzR6qife27TpX6+xTqCvMdpDuJCkiuH R1GQokrBPiPWFYVIgvxsoErmyxz4fL+43g+ha3p1Uco/2flxq9pm5iGA+wZ8Ow== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 26 Apr 2024 05:08:36 +0200 Message-ID: <20240426030839.3001504-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240426030839.3001504-1-michael@niedermayer.cc> References: <20240426030839.3001504-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 3/6] swscale/output: Fix integer overflow in yuv2rgba64_full_1_c_template() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PegY7FGS7o+C Fixes: signed integer overflow: -1082982400 + -1079364728 cannot be represented in type 'int' Fixes: 67910/clusterfuzz-testcase-minimized-ffmpeg_SWS_fuzzer-5329011971522560 The input is 9bit in 16bit, the fuzzer fills all 16bit thus generating "invalid" input No overflow should happen with valid input. Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libswscale/output.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 0b6c77e167d..b234f9c6b9a 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -1429,7 +1429,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, if (uvalpha < 2048) { for (i = 0; i < dstW; i++) { - int Y = (buf0[i]) >> 2; + SUINT Y = (buf0[i]) >> 2; int U = (ubuf0[i] - (128 << 11)) >> 2; int V = (vbuf0[i] - (128 << 11)) >> 2; int R, G, B; @@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -1462,7 +1462,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; int A = 0xffff<<14; for (i = 0; i < dstW; i++) { - int Y = (buf0[i] ) >> 2; + SUINT Y = (buf0[i] ) >> 2; int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3; int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3; int R, G, B; @@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; B = U * c->yuv2rgb_u2b_coeff; - output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16)); - output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16)); + output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16)); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4;