[libcamera-devel] Avoid segfault with bad configuration
diff mbox series

Message ID ZXt0yJ2dqUIn6Ari@duo.ucw.cz
State New
Headers show
Series
  • [libcamera-devel] Avoid segfault with bad configuration
Related show

Commit Message

Pavel Machek Dec. 14, 2023, 9:34 p.m. UTC
Without this patch, I get segfault instead of "Failed to get default
stream configuration" message.
    
Signed-off-by: Pavel Machek <pavel@ucw.cz>

Comments

Milan Zamazal Dec. 15, 2023, 2:21 p.m. UTC | #1
Pavel Machek via libcamera-devel <libcamera-devel@lists.libcamera.org> writes:

> Without this patch, I get segfault instead of "Failed to get default
> stream configuration" message.

It works for me, but ...

> Signed-off-by: Pavel Machek <pavel@ucw.cz>
>
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index bdc7bfe5..8a315bfd 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -1138,6 +1138,8 @@ SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo
>  	 */
>  	for ([[maybe_unused]] StreamRole role : roles) {
>  		StreamConfiguration cfg{ StreamFormats{ formats } };
> +		if (!formats.begin()->first)
> +			continue;

... shouldn't the condition be

  if (formats.empty())

?

And couldn't the check be applied on the whole loop (which looks weird to me
anyway and the preceding todo comment most likely applies)?

>  		cfg.pixelFormat = formats.begin()->first;
>  		cfg.size = formats.begin()->second[0].max;

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index bdc7bfe5..8a315bfd 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -1138,6 +1138,8 @@  SimplePipelineHandler::generateConfiguration(Camera *camera, Span<const StreamRo
 	 */
 	for ([[maybe_unused]] StreamRole role : roles) {
 		StreamConfiguration cfg{ StreamFormats{ formats } };
+		if (!formats.begin()->first)
+			continue;
 		cfg.pixelFormat = formats.begin()->first;
 		cfg.size = formats.begin()->second[0].max;