From fd4ce7e76a20b40c428293291fcb0e4488c122c8 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Thu, 27 Jun 2019 13:02:26 -0700 Subject: [PATCH] Camera: VTS: Don't access invalid resources There is no guarantee that the static metadata pointer passed in the "DeviceCb" contructor will be valid after the call completes. The device callback instance is expected to be active until the camera session is open. Clone the required metadata in "DeviceCb" and manage the lifetime appropriately by using the "CameraMetadata" wrapper. Bug: 135976837 Test: CameraHidlTest#processCaptureRequestPreview Change-Id: Idd3c6c8c2e5a3fc44a49712e25a04009cbd471b1 --- .../VtsHalCameraProviderV2_4TargetTest.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp index 86c2c1e15c..3cbcc7bf08 100644 --- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp +++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp @@ -607,7 +607,9 @@ public: struct DeviceCb : public V3_5::ICameraDeviceCallback { DeviceCb(CameraHidlTest *parent, int deviceVersion, const camera_metadata_t *staticMeta) : - mParent(parent), mDeviceVersion(deviceVersion), mStaticMetadata(staticMeta) {} + mParent(parent), mDeviceVersion(deviceVersion) { + mStaticMetadata = staticMeta; + } Return processCaptureResult_3_4( const hidl_vec& results) override; @@ -631,7 +633,7 @@ public: CameraHidlTest *mParent; // Parent object int mDeviceVersion; - const camera_metadata_t *mStaticMetadata; + android::hardware::camera::common::V1_0::helper::CameraMetadata mStaticMetadata; bool hasOutstandingBuffersLocked(); /* members for requestStreamBuffers() and returnStreamBuffers()*/ @@ -1194,18 +1196,20 @@ bool CameraHidlTest::DeviceCb::processCaptureResultLocked(const CaptureResult& r // Verify final result metadata bool isAtLeast_3_5 = mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_5; if (isAtLeast_3_5) { + auto staticMetadataBuffer = mStaticMetadata.getAndLock(); bool isMonochrome = Status::OK == - CameraHidlTest::isMonochromeCamera(mStaticMetadata); + CameraHidlTest::isMonochromeCamera(staticMetadataBuffer); if (isMonochrome) { mParent->verifyMonochromeCameraResult(request->collectedResult); } // Verify logical camera result metadata bool isLogicalCamera = - Status::OK == CameraHidlTest::isLogicalMultiCamera(mStaticMetadata); + Status::OK == CameraHidlTest::isLogicalMultiCamera(staticMetadataBuffer); if (isLogicalCamera) { - mParent->verifyLogicalCameraResult(mStaticMetadata, request->collectedResult); + mParent->verifyLogicalCameraResult(staticMetadataBuffer, request->collectedResult); } + mStaticMetadata.unlock(staticMetadataBuffer); } } @@ -5402,7 +5406,7 @@ void CameraHidlTest::configurePreviewStream(const std::string &name, int32_t dev ASSERT_EQ(Status::OK, s); staticMeta = clone_camera_metadata( reinterpret_cast(metadata.data())); - ASSERT_NE(nullptr, staticMeta); + ASSERT_NE(nullptr, staticMeta); }); ASSERT_TRUE(ret.isOk());