From patchwork Tue Dec 17 14:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Bouyer X-Patchwork-Id: 22376 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 332FCC32F6 for ; Tue, 17 Dec 2024 14:02:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B595067FD4; Tue, 17 Dec 2024 15:02:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="GmLh1/V0"; dkim-atps=neutral Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2061d.outbound.protection.outlook.com [IPv6:2a01:111:f403:2607::61d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BEAE267FCC for ; Tue, 17 Dec 2024 15:02:39 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BmTZRykEvInWkTynRrPnKeLVLca6bmdKEzld9AnfmepCQifLt/F8WONZXjdcei32u4SIMMCFq+V7RerjpD2lRUW8sBtOrg122QCdNSl/fTR1aiUZNPwM0IOmbI4rbkp5xkY1Th0akIqLH3YNKGSdDozN6ADnY+J6ITujK75N6o2vROr9LWfQ1pa6hwDfPP8ZxpU47w3NrPlf8byzAIkqLWA4qOzIUVgRqfz2PmQ8TRKlp3GjY0P53ewHShR29jEDdWHthieKlHwkC8k9DZAzV0MLKZbcKrMhyACCWVCSM+gJZAiJwjXv7bFSs/74ZjfDzWFqxMIlsaiMDnwsqoIx4A== 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=ndGrfVW1GzeIgC6zeR5a/3HMr59iR2Lxk3QTbZ7TFdI=; b=FYUja69HiXIb++ekqpi38HGXgzlyjyrinebUmewDlJx5P2lT6coTfeJPPhz7MQE0+seGklgox8L+LTTnVYqL980cnWuPwjUCCeTgXZvbsgG5K04oT9g842iALZcm5/PVGf7s3HeC6ILkTomUqer3x73OWNsQqKNVykgwGQ4qEWSsWXz5hn/WIXyO6COKlth8KeeqY7HaWOgpMHzV+HdJLQdyOdFhNREu7XHA9ZjMhvcEBSZFKBwqI5qVf7MomBCAO5kJedSZOy4hVmEvYXI+dA+MLhR/1SZWnsYnCEA2hEW+gN4AlvzBEBq+wjp9C6Yv+zbRwClUSGF9rJPBKpLZdA== 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=ndGrfVW1GzeIgC6zeR5a/3HMr59iR2Lxk3QTbZ7TFdI=; b=GmLh1/V0scw1xHeN7IsKJqt+V6vxoUfaipKtn8I7g7UMmLNzhfz+sh0BHn7eXPyBJVFOR8BL23JxhcNaYWqCnFn9MzMDJ5UANbaH6lwarAFRxgbHZuMTSGBxkOMycagX29+n3NsvQVoyE++VBxn8hO9bzdk5FZ8pB7aW5DroPWO1F3aBwN8Z1b8Sp41s/EPR815cDC4mHbx89HfaHqLWq3GRXyVDwUL96Y5mDpyx3dAjhR1ZwAVME7mRgALw+axveNAAY3pyqwiKobSCXHLFW2XZgIjUdPPP+7F58ViDOE3l/ZzRNRfBTH/Jo1oY8def0S0NIO1TpF1kgPH5RbybhQ== 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 AS5PR04MB10000.eurprd04.prod.outlook.com (2603:10a6:20b:682::19) 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 14:02:38 +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 14:02:38 +0000 From: Antoine Bouyer To: libcamera-devel@lists.libcamera.org Cc: julien.vuillaumier@nxp.com, Antoine Bouyer , Kieran Bingham Subject: [PATCH v2 1/1] apps: cam: kms_sink: Verify colorSpace presence before dereference Date: Tue, 17 Dec 2024 15:02:39 +0100 Message-Id: <20241217140238.215572-2-antoine.bouyer@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241217140238.215572-1-antoine.bouyer@nxp.com> References: <20241217140238.215572-1-antoine.bouyer@nxp.com> X-ClientProxiedBy: SA9PR13CA0153.namprd13.prod.outlook.com (2603:10b6:806:28::8) To GVXPR04MB9831.eurprd04.prod.outlook.com (2603:10a6:150:11c::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GVXPR04MB9831:EE_|AS5PR04MB10000:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cb2d157-db49-4a61-5f45-08dd1ea376e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: zsUfRm61FZAxwY7L+S4Ku61tzY9cbV6Vku4JSHteXbLN9u793BemCpwwijtL6HWTYIDIfL4HpBemnD9IY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nnN0kYI3m10lNS1biyw6kGhDI9jnFdUbTLRadY9FESdxCFm3owhiPm4gxpgwKdx7YEUNOZJ0+svf4koayckNQnFC8qy3w9j1hWalYbfvqqsnNzdtYDcRqgrxN37vTIFzb/C/0/HP4hTwgX/S0wlctaqYOn7b/IYo0eoFqqh/u9arfEwUa3FaxPd3navjFi+Rj+GNufG6LczAxecoh0HJotDDc7jWwPyN5XQzH+hB4xLGs3YTZncCC8QQ1T5UNwLX7BUIokR72qMBjHlng== 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)(376014)(1800799024)(52116014)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +Ajnzmd6TmzrkBRA0IMviLJR8yqJhHgPl5x1WBjfpYO49wQldlSXHd73sx9w+F4yHR66zNXFFJhpwgN+RNZmrFDOe3+VHTd4zQUkR+3eAb2bqimKqV9EcS9e5bMPGHbWu5LAou8JUJ3PW7aTVyytaTx/GA01QJwwha/Mbd28cyWqhygq3gLeym3dAapICe078aF31kkhZPt82+UbKkPgq/UwWPMc6l/CuQINuSfNMApKjscUlOSTB+i/Cs3YS9RM0lfwnGUaV+NlKS8e3zzgGt6m4CnFqtridyxRMaUOw8uHz9AtL7+NTB/dRyi/VshlBgVG++raFnQv42YHNu82Lxd/WYKP0ldrZZ1G6boa44h2j8xKbhvHkUUy29J+P/PCctMEpVDRmlTWWlv54bAJG2CvMGHyryfM9vuY11ddGVWKMoFaMkEmaYzPQDFGhrDSkVfc9Qk3zWs9QuBZFHPWZ6lAmfnjl9QKjaF18hWjlUY6voatihoC04npLmoALYjRiLNGnh0UY9/XULAgWSQNxBkrV/dw4Y4acKN5iBYqIdcBGYPXE+hS8Knh4J1KdzHtjuaPafmpQPjb343tlItR0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08dd1ea376e4 X-MS-Exchange-CrossTenant-AuthSource: GVXPR04MB9831.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 14:02:38.2653 (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: zo0bJNNcLZktlVRWkWEzL1kO7kUKle944KX9ty/hny/rKTIDXOVsGnI17zP3n0PRpxJ8YmhX1FOO86Zf0xdFnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS5PR04MB10000 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" During configuration stage, kms_sink doesn't check optional colorSpace parameter is valid while dereferencing it. Then it leads to a crash with below signature if parameter is not defined: /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) This behavior is confirmed in the "operator->" page: (https://en.cppreference.com/w/cpp/utility/optional/operator*) "This operator does not check whether the optional contains a value!" This crash is observed with styhead's gcc compiler (version 14.2.0), while it was not with previous scarthgap's gcc compiler (version 13.2.0). Use has_value() as a fix to make sure this property exists and prevent crash. Fixes: 6d7ddace5278 ("cam: Add KMS sink class") 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; /*