libcamera: converter: Check converter validity

The ConverterFactoryBase::create() function returns a nullptr when no
converter is found. The only caller, SimpleCameraData::init(), checks if
the converter is valid with isValid(), but doesn't check if the pointer
is null, which can lead to a crash.

We could check both pointer validity and converter validity in the
caller, but to limit the complexity in callers, it is better to check
the converter validity in the create() function and return a null
pointer when no valid converter is found.

Signed-off-by: Suhrid Subramaniam <suhrid.subramaniam@mediatek.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Suhrid Subramaniam
2023-03-02 11:06:29 -08:00
committed by Laurent Pinchart
parent 1957219d7e
commit 16546269aa
2 changed files with 4 additions and 2 deletions

View File

@@ -227,7 +227,9 @@ std::unique_ptr<Converter> ConverterFactoryBase::create(MediaDevice *media)
<< factory->name_ << " factory with "
<< (it == compatibles.end() ? "no" : media->driver()) << " alias.";
return factory->createInstance(media);
std::unique_ptr<Converter> converter = factory->createInstance(media);
if (converter->isValid())
return converter;
}
return nullptr;

View File

@@ -493,7 +493,7 @@ int SimpleCameraData::init()
MediaDevice *converter = pipe->converter();
if (converter) {
converter_ = ConverterFactoryBase::create(converter);
if (!converter_->isValid()) {
if (!converter_) {
LOG(SimplePipeline, Warning)
<< "Failed to create converter, disabling format conversion";
converter_.reset();