[PATCH v2 1/1] apps: cam: kms_sink: Verify colorSpace presence before dereference
Antoine Bouyer
antoine.bouyer at nxp.com
Tue Dec 17 15:02:39 CET 2024
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<libcamera::ColorSpace, true, true>]: 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 <antoine.bouyer at nxp.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
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;
/*
--
2.34.1
More information about the libcamera-devel
mailing list