From patchwork Wed Jul 3 19:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean McGovern X-Patchwork-Id: 50307 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3303520vqv; Wed, 3 Jul 2024 12:44:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVEUwOiFaZZzQ50mac5YZDE7f/35+ffLhnr3CCmuzXSf0YG0VX4HaBnx5wADxiWC+sYY74yPzcafwaSr3G15/T75jbloPI1LieajQ== X-Google-Smtp-Source: AGHT+IGkgk5pYTd/JIq1LM4DCL76VlD70xSLTj0y7ISygCmkM5bwcHVy1Go/AJUGtsGY7iAh7YM0 X-Received: by 2002:a05:6512:36c8:b0:52e:9382:a1f with SMTP id 2adb3069b0e04-52e93820bafmr1718152e87.0.1720035849563; Wed, 03 Jul 2024 12:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720035849; cv=none; d=google.com; s=arc-20160816; b=GHiEeB2vG5XAmvSi6Rvsmp5Gn1C89/pKRgkXKjq+hudO9BO6qc/u/aE62HTWjfox/K ZGdHsCteP38LKRXtK03wQby4YPYTGzaMFzkPTdhJ59tBN01rz0rDWRu/2AazxHPPhbK6 SPtznYxt35W0l7C6dQZErMZgocDpK72i5I5MitplDuWNS/92uRN9Eb6oWcy2aq4Bk4ZD Qo8fW7eKowJadte1B4M+WudL/s8Xl7ywaIVbCSPyG5b7BQHYXQpQ+9kDUiYEExb8Sznj z3CAhQDy5h3DceUwu6H6FUVJn8RAjAFAb2gSbBtAq2vyQiI9rykLr7H4AknC0V4HQNwD D56g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=cliOdB0fMT+OrBd8bRDWaPXIipMvqi07P0ExY90tKBU=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=GuZItqcNf7xsY7/u+iMZYDUCLTLfpNYWxuwDZ+BR2mWR3lVywn8Fwup0D4HW9aeVWN nEmMboH6qL8AKLkhsgV7fpAckf6FsPKO27mrA2wp+XbaQtrcyDDgru/MlGkSu0g+AB9/ tPKNwMpIUu+mDUNmG9jcTT3jQdNYvL9CYDcVuh+Rnkv3upukUsmdAMLgySd46KheyOjr deB2a4wTuFVk8eTOqQoZnfLcJBEbi9FitF06ZnBkuQPUqxLxpZZxwmuco5XDCCF9KYMV yr3FvPRjROWDJii6WT1TyRv22QjpDXbr3sYbjDvL6eARlxCfLqlz+pDjKB+hZJ95ovO4 28Rw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=OR6S9nXY; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-58de94b8809si184705a12.194.2024.07.03.12.44.05; Wed, 03 Jul 2024 12:44:09 -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=@gmail.com header.s=20230601 header.b=OR6S9nXY; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACC3A68D9B6; Wed, 3 Jul 2024 22:08:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2BB8B68D93D for ; Wed, 3 Jul 2024 22:07:55 +0300 (EEST) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a725282b926so658683366b.0 for ; Wed, 03 Jul 2024 12:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720033674; x=1720638474; darn=ffmpeg.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=OcnoLDxXTia6g/ci6d0Bvs4I00QOBVIH6MOrdC5qUu4=; b=OR6S9nXYQxXF7OnaUESaL+6ciz8c73it5Ggwifj0AdamXNFnhGyEFymv+EuD20rLbL x6ngEl78wnLDuPkIeZ53dSIfN4QW1U37JHx3M/qG9j9daq5IjF3F5+JE3kYewk2wfL0/ Q/VN4lc/XLAf6WmyW0IQmDkA8CS/2zVFSXGfPuU9TEdqrUsF12nl4L3hvFIiUsAfnEai Lq+kKG41nPS95W8rNXL+ipmwSkcOcHjLQiE/QmrecAVW4rHtarbQdY7BVpwUIhXfqu/B LZC6/AYqgk0++d90el71lVWWzJmeGJ6w37qFQH5RtUDJ8VuKR3hU0tEOA6jWcPHpAj9A 7jgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720033674; x=1720638474; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OcnoLDxXTia6g/ci6d0Bvs4I00QOBVIH6MOrdC5qUu4=; b=jkC6vutCBcllVhllcmBv7SjzC04WaApIQoe2w2HAB54URktbeiD5UXy97DuTya8fO2 xFOQ/Ejfxn873lS1oRNLFrl4KezQt3q/Kkc3a90A7AI8PybvtKaVxJOndTGUACjCybBr wgDz7JaVzUrx3+coZOARfDnx6ud9BDOx6XzcY01sNC8si0E8yM0CzdsfDBt6kZOfN6mF oQsa79zWtliYfjhATtSlrxDrQlW69lGPKwIZfpm5vxs2fALgZXarEg4NQlud1A5BuwUE 6zzI08K+WWVOU+FS/smIbL/i5o8EOV+0cs3S/PlEZYJUM8tUJHrOHFUpapNi/DJDSRTW ig9g== X-Gm-Message-State: AOJu0YwoYIhVg5tSq8kBMWBHYcsEIHzCEbaeCdvXCtOr1j7sA1aYVBxg WudThTXM4QlRtwK99mEANAuK2Ad2oADN4L8rBNNuuGsgf4BxQNem853BZlhjgf1kpkGK4R1j7Sp DnFSwfU0nAMn4YJoAHEvYjB8WPcUbLGB5 X-Received: by 2002:a17:906:4ec9:b0:a6f:6f4a:b24d with SMTP id a640c23a62f3a-a75143e70b5mr672406866b.27.1720033673733; Wed, 03 Jul 2024 12:07:53 -0700 (PDT) MIME-Version: 1.0 From: Sean McGovern Date: Wed, 3 Jul 2024 15:07:42 -0400 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [RFC] fix UB in fate-checkasm-sw_yuv2rgb 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: CwCr4K/WBWNd Hi, Attached is an RFC patch to address the undefined behaviour from the new `fate-checkasm-sw_yuv2rgb` test seen on both the x86 and ppc UBSan FATE nodes. -- Sean McGovern From 7b7c5fe69443085250ce8fc3511dddd0cfa2d756 Mon Sep 17 00:00:00 2001 From: Sean McGovern Date: Tue, 2 Jul 2024 23:07:54 -0400 Subject: [RFC PATCH] swscale: prevent undefined behaviour in the PUTRGBA macro --- Notes: Sending this as an RFC as I'm not sure it is the correct fix. It does address the undefined behaviour of the C version of yuv2rgb tested in 'fate-checkasm-sw_yuv2rgb', but since swscale new territory for me I'm not sure what I propose is appropriate. I think the AltiVec version will still need a fix after this, and Ramiro suggested there might be an issue in the LoongArch version as well. Conversation points: - Is usage of '__typeof__' OK? Is it a GCC-ism? In the rest of the codebase it seems to be limited to AltiVec acceleration. - Should this instead just cast the shifted arguments to 'int32_t' and be done with it? Aside: the macro soup in this file has very high cognitive complexity. libswscale/yuv2rgb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index 977eb3a7dd..ab5192aab4 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -100,9 +100,9 @@ const int *sws_getCoefficients(int colorspace) #define PUTRGBA(dst, ysrc, asrc, i, abase) \ Y = ysrc[2 * i]; \ - dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << abase); \ + dst[2 * i] = r[Y] + g[Y] + b[Y] + ((__typeof__(*dst))(asrc[2 * i]) << abase); \ Y = ysrc[2 * i + 1]; \ - dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << abase); + dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + ((__typeof__(*dst))(asrc[2 * i + 1]) << abase); #define PUTRGB48(dst, src, asrc, i, abase) \ Y = src[ 2 * i]; \ -- 2.39.2