From patchwork Tue Dec 17 09:51:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Bouyer X-Patchwork-Id: 22373 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6F843C32F6 for ; Tue, 17 Dec 2024 09:50:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4986367FC1; Tue, 17 Dec 2024 10:50:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="eoBvHFjN"; dkim-atps=neutral Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062a.outbound.protection.outlook.com [IPv6:2a01:111:f403:2612::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6382A61899 for ; Tue, 17 Dec 2024 10:50:39 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XNwJTfCY2eaKRY7RShuJSMKtFHH9wCefRqrMyCj318HOEHmLEmPIlinz29+keRD2gwI8gK+6kbh7qg3DDulCzmjzn8JkhhsaJHVMPQ3XegEkCt1jw9v5c1BjTDQ+ExUYmQsxQBOqc9xwntea81Ydrbl10w9OP9tWcCzH3rVBG44oDKSO2GQzQPugppQ89AphT0BfqFBvKHteQssQhafoprWEuI7sCOpEgliHtkVqm1AVoOY4UH+3Gt4f8EaW0FNyCDUhdho2KKXNt7RYB9XfDcCvSXPrbgl1QcT3nz/B40akmzJNpnuD1lu4EUBQVfpb2LXcWP7SJYN3HkRhlMyEWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9IdFbLivdQyCtrc/qY9rhRjQMX1BjqLux0tJbjc7BnQ=; b=uPrqgJx65Bz5+AieNuFf1KKITi0ZLyy6nd3E8uFftrpatXbeU2bkarYmby7eNl0l3FDU9LliqzjScKnuIGgyKktre2sXw+vDHDzXrLJfLabpksMYR5CLTslvJIpvo8CUDk/g7GYyqPOLFwxrgj4/7l08UWM23GGCP1m89N5Tb949dl8/mQVNSpeUFTTFRgI8FkRG2i4qHznVCpCjoa73UzhJdp2WSLjceu+jHkxxiEHsfbQBIjOJuQYSWPl7kfPPA4SRc+loLsy/1yNnKJLnTdlldWoB2x0VDTH/Uw9jW8QxXvbbjDqQnWs8CUK0NRxpD6gSifBzjY7ghAY6KBCl0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9IdFbLivdQyCtrc/qY9rhRjQMX1BjqLux0tJbjc7BnQ=; b=eoBvHFjNWKxj4maCNxs06YvohYfqG0yPp4LzXBvvjXzp07k39whe8TcvnDjWe6VUCp9N1oi9Yb0IgaqCLJbah+EMZ0/hjU0ZBGcd11cgUtH7BBYFyn5hVPIu3BpCK8NWTI6iPo+RgpsyHYsqvBYHzcgrtiADkMUDrSfZkSDWMIFXJRrd9WZj2MlW8kKJ7ZdMpT4ttjUclAxN61cHZv4ae1kAKi3GJPU5eoZKuYZrm34OeAF/uoR8dm98Ufe5I5IFRYxXqCWccXsXWDXmr9hKRnjfGUjCkiUTN/RnT/xtKC3BEVIv+7AAUignOLuXKSdF1gMbSv4pcI9FjLtuIabF8Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from GVXPR04MB9831.eurprd04.prod.outlook.com (2603:10a6:150:11c::8) by VI2PR04MB10287.eurprd04.prod.outlook.com (2603:10a6:800:220::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.21; Tue, 17 Dec 2024 09:50:37 +0000 Received: from GVXPR04MB9831.eurprd04.prod.outlook.com ([fe80::4634:3d9c:c4a:641a]) by GVXPR04MB9831.eurprd04.prod.outlook.com ([fe80::4634:3d9c:c4a:641a%7]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 09:50:36 +0000 From: Antoine Bouyer To: libcamera-devel@lists.libcamera.org Cc: julien.vuillaumier@nxp.com, antoine.bouyer@nxp.com Subject: [PATCH] apps: cam: kms_sink: Verify colorSpace is defined before dereferencing to avoid undefined behavior Date: Tue, 17 Dec 2024 10:51:37 +0100 Message-Id: <20241217095137.132370-1-antoine.bouyer@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BYAPR08CA0030.namprd08.prod.outlook.com (2603:10b6:a03:100::43) To GVXPR04MB9831.eurprd04.prod.outlook.com (2603:10a6:150:11c::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GVXPR04MB9831:EE_|VI2PR04MB10287:EE_ X-MS-Office365-Filtering-Correlation-Id: b62099da-acf4-44b6-f865-08dd1e8041b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|366016|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: falCON4rDUpDtUSdZrsY+9CiHYY9/MT6qvnnYh1LFtq7/09dSG2r+MAaUf7uv3Hj93fIsF0W5hvcO91i+Edy2Vdz/pN4boVwILK7vdGdcnUuODBNyd0gHqIUBDttdVKzhMkMlaAmgxsHI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0+o0twMxwK9JAEOKi5jcvf7YI14svkEbGoBBObXHCGJ7NIr8FOpSiu0vSRwNmjzpVHE5jndKJviwnNYZsjWcVcX9owwXvGgHcs6w3MRIxoo6OKAGjpfIm3D/B65Sa/isir2ZBH7GAyUuG4rNAOpYicY3GbIp6irJgOPCa96uVnHFOr9PItreFGVwoa5XmqZmLB8CWcpVN4L2NTdmQPNw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:GVXPR04MB9831.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(52116014)(366016)(376014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1aNPdIsBEqfDrDQzVSnzKN07ntFinPDWbKZT6NhFeUJHNp58vZDY39quVtxUMcZfzts3ea/AzioOuCVbcAT/kpbe6Te01pLdfBhNerFCers2cIqyTe0agwj1AfqxVRw2Mf2Iympl79slb+A3kb3IFXgXf8am6T6Tx9cp9m85XU69mC1lytixiSZ8eMQj9uaxws/WWK7+0Xs6tIEb6WSLZgFO/fh+nXOss9owVAL0hNIgojDFOzeiCxzBJ1ZZaxhyFgYscnZM5X2D9OMmyj39z8BcvPRoYyl7dobkuzUiaKPA5y+oZUrUJl++uhadCQR3z5MKvVEXsgO4XpX5wi72iv3cro9ELyoDzOudimRZ8Z9GY7G9KewEGYvT9wOFnWq9e+JpKnyllWXecq/j40J8ws3Tlq45ykm61L49gphgRx5gFORcvZ7q1qJgfyFZcucVyHSn0IPX6zED6P8Gnw2HD8VXR1l3pX3CcJhj6nRRZ+EwzHgl1bJ6NL1OsDnuzF2TLiRkgeZgay6DTnE6+LWYYvpbeaxUCx/xQx8fE1gdwH9XzPPJ9pJpZG4Um4+EPiZTLp8el5nlpJtd9R8nhKEqGq+X9F28QQGEUQKFpqCYxGQXim+WI3k/aGCsBkLHzF56znfnK07BCHvnV8JI3HdZUY+zN2U2lAYueXBbkdvDL9rNm8Cvto8g9efUrzLW4A7Dx356QUCubmK7vl1kyMEAilhjQcy9/zl3Hc1yRyTD5Jx5m/PGDVTpZpOdayktClxybyAo38sQhZ97tT6/a0gDkkGtPsGjZTtnKElHcXq0gi5ZNHZ9Q/gDZCBxxTbPi89404pe5Fp10iAwvm9tBTHtcYdDXr1h+H5rEwhlksnyVe7sJunkM3vYIbTteuaMcWiNGH7vJ1fK/ldp+NI7uJpXbFI7R0v9ELOfQegZ0nzVtmDyqlVe7WIp+BmtYeNzzmXTqC6aYS+Mo59aG7F4Ve6mL6pnWGf20Zja/MuEs5RFfm0UwauQeEAS3hn2pVOtSSygobArL1rJ6ewcFoWhTNk0hpdJZvtcq5Ne4N3FdTx1Pq93AU96EBuJqD9icBwHJUBCAd4kTk4s75i3VK10ovBBGbRwmAEXPSyw+QwebLBD0ULdfZ75In0MvalGw9lLTresM6gvnxgKGqgZcDRB1o6CF2EhEB5L/qHMr3nWLKGZ7h34Uq81Jutoqpqx3tDhnbOgWBILiwkNdsAs9lf7Jwlg0IiV1cUHzoJe/AYuNX8RcreMJT5gmlDF2uSKmk5j05kmcI/FDZJLurd2pnfzECbgCcJU9KgGwndeJfNpsL3rcqboPWkTXGph9xgNcqNSK5CuDy4zDve+kt8Ez1bS9qAVmf4pbfIp8fdcIMEa2H2nGyxNXLQoslEdhKJy7nIzqsj+YNP+Uow+wP7cKJxovshgapQlhzdVwD/9LLywLZY+uq1UHMgmbqf17CdYOqsgMzofz2KhsXucwHrv7RyvS7Al7RHycbILRbiF0muJBN2LncqtSNawerYjvzvwjybktpZkIHmXC3YQOYEUpn09PbS8Ya5ybyhvJgCl1ZfDWfza8b726z554tLnAgJFHgXdnr5MkBiIRPv6UcGDu8nr/lbG9A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b62099da-acf4-44b6-f865-08dd1e8041b7 X-MS-Exchange-CrossTenant-AuthSource: GVXPR04MB9831.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 09:50:36.7319 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Hlsmj/zWB8Y/DiEy/t4GlU3s/GGtIvbquMksPqz/Mejd6QKQka/UD52lo5ymybj4ale8DFknWiEgdpopMiZPGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI2PR04MB10287 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch fixes below crash, with styhead's gcc compiler (version 14.2.0), which occurs when optional colorSpace parameter is not filled. /opt/fsl-imx-internal-xwayland/6.12-styhead/sysroots/armv8a-poky-linux/usr/include/c++/14.2.0/optional:48 2: constexpr const _Tp& std::_Optional_base_impl<_Tp, _Dp>::_M_get() const [with _Tp = libcamera::ColorSp ace; _Dp = std::_Optional_base]: Assertion 'this->_M_is_engaged()' fai led. Aborted (core dumped) As detailed in the "operator->" page: (https://en.cppreference.com/w/cpp/utility/optional/operator*) "This operator does not check whether the optional contains a value!" Use has_value() as a fix to make sure this property exists and prevent crash. Signed-off-by: Antoine Bouyer Reviewed-by: Kieran Bingham --- src/apps/cam/kms_sink.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/cam/kms_sink.cpp b/src/apps/cam/kms_sink.cpp index 672c985..8f3b867 100644 --- a/src/apps/cam/kms_sink.cpp +++ b/src/apps/cam/kms_sink.cpp @@ -153,7 +153,8 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config) colorEncoding_ = std::nullopt; colorRange_ = std::nullopt; - if (cfg.colorSpace->ycbcrEncoding == libcamera::ColorSpace::YcbcrEncoding::None) + if (!cfg.colorSpace.has_value() || + cfg.colorSpace->ycbcrEncoding == libcamera::ColorSpace::YcbcrEncoding::None) return 0; /*