[libcamera-devel] [PATCH] android: camera_device: Fix crash of accessing a missing map element

Hirokazu Honda hiroh at chromium.org
Wed Oct 28 09:57:26 CET 2020


std::map::at() searches std::map by the given key. The commit
e1f9fdb8a5bd096faa34d54804afa48d46d59b28 uses it with 0 to intend to
accessing the first element of the map, but actually access the
element whose key is nullptr. This causes the crash because the map
doesn't have the element with nullptr. This fixes the issue by
replacing the std::map::at() operation by std::map::begin().

Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
---
 src/android/camera_device.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index ca60f51..ead8a43 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1525,7 +1525,7 @@ void CameraDevice::requestComplete(Request *request)
 	 * It might be appropriate to return a 'correct' (as determined by
 	 * pipeline handlers) timestamp in the Request itself.
 	 */
-	uint64_t timestamp = buffers.at(0)->metadata().timestamp;
+	uint64_t timestamp = buffers.begin()->second->metadata().timestamp;
 	resultMetadata = getResultMetadata(descriptor->frameNumber_, timestamp);

 	/* Handle any JPEG compression. */
--
2.29.0.rc2.309.g374f81d7ae-goog


More information about the libcamera-devel mailing list