From patchwork Wed Oct 26 16:17:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Drew Dunne X-Patchwork-Id: 39015 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:85a8:b0:a2:d5a7:ad9d with SMTP id s40csp301367pzd; Wed, 26 Oct 2022 09:18:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nRQIp0xTyQCbTRkTKKNjzkTnaSsgwFvnMkynVZBBLaPUyZIs8lYlzuN/3HQHx3l9MFGK3 X-Received: by 2002:a17:906:478d:b0:7a3:cf5e:9027 with SMTP id cw13-20020a170906478d00b007a3cf5e9027mr18554818ejc.718.1666801099846; Wed, 26 Oct 2022 09:18:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666801099; cv=none; d=google.com; s=arc-20160816; b=OybcgruNABiICvjzcY7vg+UUitG0pnuWVTk/bYb9/0kwhhyboGOElvtg4Oy9VLb3oe BgA/5nNwzVVWXaE5iSshztFj8cewVsYnkOC/JX5AN/H7DAL7l/E4gRkOPeLudmblD6vk e+uD7hOmPXXRpbXCKWxbfkBobquc9eT0yqLd7lQEtqpL5KzFmsKT/9KtO72r2x1DlzLz 6S28fnfNLbrmRFzHKjuLoiHNwR5cU+CwB/cSotv1AooCzQ2MaVKDzvzFFCwLHDFeFLJk 2E+2aJfukgD4Fhdnn5H0K/SzdU0BD1Vd1/axDuS3g+ShbgvxgdxELUJb5y7bLLfmt5LY IpLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:from:message-id:mime-version:date :dkim-signature:delivered-to; bh=cOC8IQ1geZ+j+XL0tsWoMj2KU+yBuglxHUJgM/NFDcI=; b=DtpJM8nffsF6N2wIDzpIgny8vr5Ff0fzqTSGSYi/S0d8aIfJ3MOBdjYyyVo/hGH3zt 2TfT1QMc8E4irC3BPTXGYm0q7W4no7GUD/dElplb8ayWhGLyO6YjmvfaRH1wmL6LcsrU pzG5wW71yBIdnzhFldEjCRH4FJFWDgdX7Mzo/fW0Xdr7UZMtIyKHWg8yLnrCGsCMkVt/ UEdfNxDzD/3ltjw1wukt+T9DbVHYtqBP6FccVfj3/7BY4ixoUNH3NHRIKTNi0inWbkb+ vycDG8rTXMOteMU1K+771PJHh68Sls0CNUw6og68AlBZF+LnoiHq0Y0rqx9mVrG+2Q0R /Mvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20210112 header.b=OaYRGB9E; 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 m3-20020a1709066d0300b007877f3132d9si463591ejr.438.2022.10.26.09.18.17; Wed, 26 Oct 2022 09:18:19 -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=@google.com header.s=20210112 header.b=OaYRGB9E; 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 1B13F68BBE5; Wed, 26 Oct 2022 19:17:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5AA7568B554 for ; Wed, 26 Oct 2022 19:17:53 +0300 (EEST) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-368036d93abso151940707b3.18 for ; Wed, 26 Oct 2022 09:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DuP357J+jFElbnr4h3zbO4B7IKDoJFpcXkCKcBGdh60=; b=OaYRGB9Exj1kiVNnJc2OGt3TfNw6GAm8iTna/6iy1v6ZYezSZ5GkQ2tWHhy+9Qr3Yf 54iMuo4fL+e+gUfkEIWuLgcxlQmTykTVvo9Zc8r0wec+KAOccODil+F/IjFsKUt79qu+ aWeNy0QPInerxhDc8PWR7RIm5EhZDYsS5GaBFBTQW1nPHbcO4Os7MdXqpBbWUI3/6jrc ZhYBeRCP/Zja0jH630p1qfFKa1U8fTXl3Qt4g/UkH2lkFvWtupNDLPR0jdwK4sLovtKT DLPVFIyUHok168k8ujJgpKpf829Beu5V4hhIJ5iQ/JIxQOlFCC7bkYyamtCXUEjf3jbA scLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DuP357J+jFElbnr4h3zbO4B7IKDoJFpcXkCKcBGdh60=; b=JAx6CZpcOIGyhsP42q9LJ3aUhhhImrXeeeB53AADg1Xgt12d1G8IJbPB7xUAFrHEvw E2PTdQXnGL/vfAU4X+F7TBSW7E/OmOhMIxPxSgRUhOKYoO7XodcByF+67f5K62ki5SM1 Kdn6BNkd9nx7IZO1gMKbq6kr20wwN2HGfkP+Oo0ldQO0lYtfZ575QRtVudBS1FHMhZVs M5E16E/IlH/HdTGnLiCx+Ec43qCaOyXG+HJT3R59JkMSm3h5utrYGQc1xzr/2eHxWirv iJQjvApeSHyacrWC2FA1Rv2rkSp/LLQ0FhC5yyhYhrMEI+L29Gvd8rl8XsDRZKcytP+Y V59g== X-Gm-Message-State: ACrzQf1uNLsbskvsfllXQqaCtcC4M6tpyw8bd1rszPJHMx+rvL2N1kiN vY3sDttwq2fKE4T9UkZjzcqNSFqr1vx1IL9TKEJiiGQtfC8dY8d7TbWsK1glZnVQvV03ebkjCD0 tmPMX5j/bAzdpMet5pAadF9NHcCW0SYQA4NQPD4hu4djbnlAu+GIzKQ4K+BgIxAywHg== X-Received: from zaffrezebra.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2d40]) (user=asdunne job=sendgmr) by 2002:a25:fc04:0:b0:6ca:55d:3af2 with SMTP id v4-20020a25fc04000000b006ca055d3af2mr36144285ybd.532.1666801071761; Wed, 26 Oct 2022 09:17:51 -0700 (PDT) Date: Wed, 26 Oct 2022 16:17:47 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221026161747.3672520-1-asdunne@google.com> From: Drew Dunne To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Avoid possible integer overflow in yuv420 to rgba64 templates by saturating. 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 Cc: Drew Dunne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ls5sKitdIxlo --- libswscale/output.c | 96 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 0e1c1225a0..8c8f62682a 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter, B = U * c->yuv2rgb_u2b_coeff; // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits - output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y1), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); dest += 6; } } @@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2], A2 += 1 << 13; } - output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y1), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); dest += 6; } } @@ -1232,20 +1232,20 @@ yuv2rgba64_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 + Y1, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y1), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); dest += 6; } } @@ -1278,20 +1278,20 @@ yuv2rgba64_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 + Y1, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y1), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); dest += 8; } else { - output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); - output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); - output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); + output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14); + output_pixel(&dest[4], av_clip_uintp2(av_sat_add32( G, Y2), 30) >> 14); + output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14); dest += 6; } } @@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter, B = U * c->yuv2rgb_u2b_coeff; // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit - output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2], A += 1 << 13; } - output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -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, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4; @@ -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, 30) >> 14); - output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14); - output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14); + output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14); + output_pixel(&dest[1], av_clip_uintp2(av_sat_add32( G, Y), 30) >> 14); + output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14); if (eightbytes) { output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14); dest += 4;