[PATCH 1/2] libcamera: formats: Fix planes bounds check

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Feb 26 10:48:56 CET 2024


The plane validation in the stride helper incorrectly accepts the number
of planes as a plane index. Fix the off by one issue.

Reported-by: Johan Mattsson <39247600+mjunix at users.noreply.github.com>
Fixes: e83727a194b5 ("libcamera: PixelFormatInfo: Add functions stride and frameSize")
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 src/libcamera/formats.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 447e623803c7..c11fbd730c8e 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -987,7 +987,7 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane,
 		return 0;
 	}
 
-	if (plane > planes.size() || !planes[plane].bytesPerGroup) {
+	if (plane >= planes.size() || !planes[plane].bytesPerGroup) {
 		LOG(Formats, Warning) << "Invalid plane index, stride is zero";
 		return 0;
 	}
-- 
2.34.1



More information about the libcamera-devel mailing list