Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <Camera.h> |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 18 | #include <CameraParameters.h> |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 19 | #include <CameraUtils.h> |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 20 | #include <android/content/AttributionSourceState.h> |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 21 | #include <binder/MemoryDealer.h> |
| 22 | #include <fuzzer/FuzzedDataProvider.h> |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 23 | #include <gui/Surface.h> |
| 24 | #include <gui/SurfaceComposerClient.h> |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 25 | #include "camera2common.h" |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 26 | |
| 27 | using namespace std; |
| 28 | using namespace android; |
| 29 | using namespace android::hardware; |
| 30 | |
| 31 | constexpr int32_t kFrameRateMin = 1; |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 32 | constexpr int32_t kFrameRateMax = 1000; |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 33 | constexpr int32_t kNumMin = 0; |
| 34 | constexpr int32_t kNumMax = 1024; |
| 35 | constexpr int32_t kMemoryDealerSize = 1000; |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 36 | constexpr int8_t kMinElements = 1; |
| 37 | constexpr int8_t kMaxElements = 10; |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 38 | |
| 39 | constexpr int32_t kValidCMD[] = {CAMERA_CMD_START_SMOOTH_ZOOM, |
| 40 | CAMERA_CMD_STOP_SMOOTH_ZOOM, |
| 41 | CAMERA_CMD_SET_DISPLAY_ORIENTATION, |
| 42 | CAMERA_CMD_ENABLE_SHUTTER_SOUND, |
| 43 | CAMERA_CMD_PLAY_RECORDING_SOUND, |
| 44 | CAMERA_CMD_START_FACE_DETECTION, |
| 45 | CAMERA_CMD_STOP_FACE_DETECTION, |
| 46 | CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG, |
| 47 | CAMERA_CMD_PING, |
| 48 | CAMERA_CMD_SET_VIDEO_BUFFER_COUNT, |
| 49 | CAMERA_CMD_SET_VIDEO_FORMAT}; |
| 50 | |
| 51 | constexpr int32_t kValidVideoBufferMode[] = {ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV, |
| 52 | ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA, |
| 53 | ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE}; |
| 54 | |
| 55 | constexpr int32_t kValidPreviewCallbackFlag[] = { |
| 56 | CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK, CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK, |
| 57 | CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK, CAMERA_FRAME_CALLBACK_FLAG_NOOP, |
| 58 | CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER, CAMERA_FRAME_CALLBACK_FLAG_CAMERA, |
| 59 | CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER}; |
| 60 | |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 61 | class TestCameraListener : public CameraListener { |
| 62 | public: |
| 63 | virtual ~TestCameraListener() = default; |
| 64 | |
| 65 | void notify(int32_t /*msgType*/, int32_t /*ext1*/, int32_t /*ext2*/) override { return; }; |
| 66 | void postData(int32_t /*msgType*/, const sp<IMemory>& /*dataPtr*/, |
| 67 | camera_frame_metadata_t* /*metadata*/) override { |
| 68 | return; |
| 69 | }; |
| 70 | void postDataTimestamp(nsecs_t /*timestamp*/, int32_t /*msgType*/, |
| 71 | const sp<IMemory>& /*dataPtr*/) override { |
| 72 | return; |
| 73 | }; |
| 74 | void postRecordingFrameHandleTimestamp(nsecs_t /*timestamp*/, |
| 75 | native_handle_t* /*handle*/) override { |
| 76 | return; |
| 77 | }; |
| 78 | void postRecordingFrameHandleTimestampBatch( |
| 79 | const std::vector<nsecs_t>& /*timestamps*/, |
| 80 | const std::vector<native_handle_t*>& /*handles*/) override { |
| 81 | return; |
| 82 | }; |
| 83 | }; |
| 84 | |
| 85 | class CameraFuzzer : public ::android::hardware::BnCameraClient { |
| 86 | public: |
| 87 | void process(const uint8_t* data, size_t size); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 88 | |
| 89 | private: |
| 90 | bool initCamera(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 91 | void invokeCamera(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 92 | void invokeSetParameters(); |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 93 | native_handle_t* createNativeHandle(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 94 | sp<Camera> mCamera = nullptr; |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 95 | FuzzedDataProvider* mFDP = nullptr; |
| 96 | |
| 97 | // CameraClient interface |
| 98 | void notifyCallback(int32_t, int32_t, int32_t) override { return; }; |
| 99 | void dataCallback(int32_t, const sp<IMemory>&, camera_frame_metadata_t*) override { return; }; |
| 100 | void dataCallbackTimestamp(nsecs_t, int32_t, const sp<IMemory>&) override { return; }; |
| 101 | void recordingFrameHandleCallbackTimestamp(nsecs_t, native_handle_t*) override { return; }; |
| 102 | void recordingFrameHandleCallbackTimestampBatch(const std::vector<nsecs_t>&, |
| 103 | const std::vector<native_handle_t*>&) override { |
| 104 | return; |
| 105 | }; |
| 106 | }; |
| 107 | |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 108 | native_handle_t* CameraFuzzer::createNativeHandle() { |
| 109 | int32_t numFds = mFDP->ConsumeIntegralInRange<int32_t>(kMinElements, kMaxElements); |
| 110 | int32_t numInts = mFDP->ConsumeIntegralInRange<int32_t>(kNumMin, kNumMax); |
| 111 | native_handle_t* handle = native_handle_create(numFds, numInts); |
| 112 | for (int32_t i = 0; i < numFds; ++i) { |
| 113 | std::string filename = mFDP->ConsumeRandomLengthString(kMaxBytes); |
| 114 | int32_t fd = open(filename.c_str(), O_RDWR | O_CREAT | O_TRUNC); |
| 115 | handle->data[i] = fd; |
| 116 | } |
| 117 | return handle; |
| 118 | } |
| 119 | |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 120 | bool CameraFuzzer::initCamera() { |
| 121 | ProcessState::self()->startThreadPool(); |
| 122 | sp<IServiceManager> sm = defaultServiceManager(); |
| 123 | sp<IBinder> binder = sm->getService(String16("media.camera")); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 124 | sp<ICameraService> cameraService = nullptr; |
| 125 | cameraService = interface_cast<ICameraService>(binder); |
| 126 | sp<ICamera> cameraDevice = nullptr; |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 127 | AttributionSourceState clientAttribution; |
| 128 | clientAttribution.deviceId = kDefaultDeviceId; |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 129 | if (mFDP->ConsumeBool()) { |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 130 | clientAttribution.uid = hardware::ICameraService::USE_CALLING_UID; |
| 131 | clientAttribution.pid = hardware::ICameraService::USE_CALLING_PID; |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 132 | cameraService->connect(this, mFDP->ConsumeIntegral<int32_t>() /* cameraId */, "CAMERAFUZZ", |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 133 | /*targetSdkVersion*/ __ANDROID_API_FUTURE__, |
| 134 | /*overrideToPortrait*/ false, /*forceSlowJpegMode*/ false, |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 135 | clientAttribution, /*devicePolicy*/0, &cameraDevice); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 136 | } else { |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 137 | clientAttribution.uid = mFDP->ConsumeIntegral<int8_t>(); |
| 138 | clientAttribution.pid = mFDP->ConsumeIntegral<int8_t>(); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 139 | cameraService->connect(this, mFDP->ConsumeIntegral<int32_t>() /* cameraId */, |
| 140 | mFDP->ConsumeRandomLengthString(kMaxBytes).c_str(), |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 141 | /*targetSdkVersion*/ mFDP->ConsumeIntegral<int32_t>(), |
| 142 | /*overrideToPortrait*/ mFDP->ConsumeBool(), |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 143 | /*forceSlowJpegMode*/ mFDP->ConsumeBool(), clientAttribution, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 144 | /*devicePolicy*/0, &cameraDevice); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 147 | mCamera = Camera::create(cameraDevice); |
| 148 | if (!mCamera) { |
| 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | void CameraFuzzer::invokeSetParameters() { |
| 155 | String8 s = mCamera->getParameters(); |
| 156 | CameraParameters params(s); |
| 157 | int32_t width = mFDP->ConsumeIntegral<int32_t>(); |
| 158 | int32_t height = mFDP->ConsumeIntegral<int32_t>(); |
| 159 | params.setVideoSize(width, height); |
| 160 | int32_t frameRate = mFDP->ConsumeIntegralInRange<int32_t>(kFrameRateMin, kFrameRateMax); |
| 161 | params.setPreviewFrameRate(frameRate); |
| 162 | mCamera->setParameters(params.flatten()); |
| 163 | } |
| 164 | |
| 165 | void CameraFuzzer::invokeCamera() { |
| 166 | if (!initCamera()) { |
| 167 | return; |
| 168 | } |
| 169 | |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 170 | int32_t cameraId = mFDP->ConsumeIntegral<int32_t>(); |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 171 | AttributionSourceState clientAttribution; |
| 172 | clientAttribution.deviceId = kDefaultDeviceId; |
| 173 | Camera::getNumberOfCameras(clientAttribution, /*devicePolicy*/0); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 174 | CameraInfo cameraInfo; |
| 175 | cameraInfo.facing = mFDP->ConsumeBool() ? mFDP->PickValueInArray(kValidFacing) |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 176 | : mFDP->ConsumeIntegral<int32_t>(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 177 | cameraInfo.orientation = mFDP->ConsumeBool() ? mFDP->PickValueInArray(kValidOrientation) |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 178 | : mFDP->ConsumeIntegral<int32_t>(); |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame^] | 179 | Camera::getCameraInfo(cameraId, /*overrideToPortrait*/false, clientAttribution, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 180 | /*devicePolicy*/0, &cameraInfo); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 181 | mCamera->reconnect(); |
| 182 | |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 183 | sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient; |
| 184 | sp<SurfaceControl> surfaceControl = nullptr; |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 185 | if (mFDP->ConsumeBool()) { |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 186 | surfaceControl = composerClient->createSurface(String8("FUZZSURFACE"), 1280, 800, |
| 187 | HAL_PIXEL_FORMAT_YV12); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 188 | } else { |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 189 | surfaceControl = composerClient->createSurface( |
| 190 | static_cast<String8>(mFDP->ConsumeRandomLengthString(kMaxBytes).c_str()) /* name */, |
| 191 | mFDP->ConsumeIntegral<uint32_t>() /* width */, |
| 192 | mFDP->ConsumeIntegral<uint32_t>() /* height */, |
| 193 | mFDP->ConsumeIntegral<int32_t>() /* format */, |
| 194 | mFDP->ConsumeIntegral<int32_t>() /* flags */); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 195 | } |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 196 | |
| 197 | if (mFDP->ConsumeBool()) { |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 198 | invokeSetParameters(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 199 | } |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 200 | sp<Surface> surface = nullptr; |
| 201 | if (surfaceControl) { |
| 202 | surface = surfaceControl->getSurface(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 203 | } |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 204 | sp<MemoryDealer> memoryDealer = nullptr; |
| 205 | sp<IMemory> iMem = nullptr; |
| 206 | sp<CameraListener> cameraListener = nullptr; |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 207 | |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 208 | while (mFDP->remaining_bytes()) { |
| 209 | auto callCameraAPIs = mFDP->PickValueInArray<const std::function<void()>>({ |
| 210 | [&]() { |
| 211 | if (surfaceControl) { |
| 212 | mCamera->setPreviewTarget(surface->getIGraphicBufferProducer()); |
| 213 | } |
| 214 | }, |
| 215 | [&]() { |
| 216 | if (surfaceControl) { |
| 217 | mCamera->startPreview(); |
| 218 | } |
| 219 | }, |
| 220 | [&]() { |
| 221 | if (surfaceControl) { |
| 222 | mCamera->stopPreview(); |
| 223 | } |
| 224 | }, |
| 225 | [&]() { |
| 226 | if (surfaceControl) { |
| 227 | mCamera->stopPreview(); |
| 228 | } |
| 229 | }, |
| 230 | [&]() { |
| 231 | if (surfaceControl) { |
| 232 | mCamera->previewEnabled(); |
| 233 | } |
| 234 | }, |
| 235 | [&]() { |
| 236 | if (surfaceControl) { |
| 237 | mCamera->startRecording(); |
| 238 | } |
| 239 | }, |
| 240 | [&]() { |
| 241 | if (surfaceControl) { |
| 242 | mCamera->stopRecording(); |
| 243 | } |
| 244 | }, |
| 245 | [&]() { mCamera->lock(); }, |
| 246 | [&]() { mCamera->unlock(); }, |
| 247 | [&]() { mCamera->autoFocus(); }, |
| 248 | [&]() { mCamera->cancelAutoFocus(); }, |
| 249 | [&]() { |
| 250 | int32_t msgType = mFDP->ConsumeIntegral<int32_t>(); |
| 251 | mCamera->takePicture(msgType); |
| 252 | }, |
| 253 | [&]() { |
| 254 | int32_t cmd; |
| 255 | cmd = mFDP->ConsumeBool() ? mFDP->PickValueInArray(kValidCMD) |
| 256 | : mFDP->ConsumeIntegral<int32_t>(); |
| 257 | int32_t arg1 = mFDP->ConsumeIntegral<int32_t>(); |
| 258 | int32_t arg2 = mFDP->ConsumeIntegral<int32_t>(); |
| 259 | mCamera->sendCommand(cmd, arg1, arg2); |
| 260 | }, |
| 261 | [&]() { |
| 262 | int32_t videoBufferMode = |
| 263 | mFDP->ConsumeBool() ? mFDP->PickValueInArray(kValidVideoBufferMode) |
| 264 | : mFDP->ConsumeIntegral<int32_t>(); |
| 265 | mCamera->setVideoBufferMode(videoBufferMode); |
| 266 | }, |
| 267 | [&]() { |
| 268 | if (surfaceControl) { |
| 269 | mCamera->setVideoTarget(surface->getIGraphicBufferProducer()); |
| 270 | } |
| 271 | }, |
| 272 | [&]() { |
| 273 | cameraListener = sp<TestCameraListener>::make(); |
| 274 | mCamera->setListener(cameraListener); |
| 275 | }, |
| 276 | [&]() { |
| 277 | int32_t previewCallbackFlag; |
| 278 | previewCallbackFlag = |
| 279 | mFDP->ConsumeBool() ? mFDP->PickValueInArray(kValidPreviewCallbackFlag) |
| 280 | : mFDP->ConsumeIntegral<int32_t>(); |
| 281 | mCamera->setPreviewCallbackFlags(previewCallbackFlag); |
| 282 | }, |
| 283 | [&]() { |
| 284 | if (surfaceControl) { |
| 285 | mCamera->setPreviewCallbackTarget(surface->getIGraphicBufferProducer()); |
| 286 | } |
| 287 | }, |
| 288 | [&]() { mCamera->getRecordingProxy(); }, |
| 289 | [&]() { |
| 290 | int32_t mode = mFDP->ConsumeIntegral<int32_t>(); |
| 291 | mCamera->setAudioRestriction(mode); |
| 292 | }, |
| 293 | [&]() { mCamera->getGlobalAudioRestriction(); }, |
| 294 | [&]() { mCamera->recordingEnabled(); }, |
| 295 | [&]() { |
| 296 | memoryDealer = new MemoryDealer(kMemoryDealerSize); |
| 297 | iMem = memoryDealer->allocate(kMemoryDealerSize); |
| 298 | }, |
| 299 | [&]() { |
| 300 | int32_t msgTypeNC = mFDP->ConsumeIntegral<int32_t>(); |
| 301 | int32_t ext = mFDP->ConsumeIntegral<int32_t>(); |
| 302 | int32_t ext2 = mFDP->ConsumeIntegral<int32_t>(); |
| 303 | mCamera->notifyCallback(msgTypeNC, ext, ext2); |
| 304 | }, |
| 305 | [&]() { |
| 306 | int32_t msgTypeNC = mFDP->ConsumeIntegral<int32_t>(); |
| 307 | int64_t timestamp = mFDP->ConsumeIntegral<int64_t>(); |
| 308 | mCamera->dataCallbackTimestamp(timestamp, msgTypeNC, iMem); |
| 309 | }, |
| 310 | [&]() { |
| 311 | int64_t timestamp = mFDP->ConsumeIntegral<int64_t>(); |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 312 | native_handle_t* handle = createNativeHandle(); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 313 | mCamera->recordingFrameHandleCallbackTimestamp(timestamp, handle); |
| 314 | }, |
| 315 | [&]() { |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 316 | native_handle_t* handle = createNativeHandle(); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 317 | mCamera->releaseRecordingFrameHandle(handle); |
| 318 | }, |
| 319 | [&]() { mCamera->releaseRecordingFrame(iMem); }, |
| 320 | [&]() { |
| 321 | std::vector<native_handle_t*> handles; |
| 322 | for (int8_t i = 0; |
| 323 | i < mFDP->ConsumeIntegralInRange<int8_t>(kMinElements, kMaxElements); |
| 324 | ++i) { |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 325 | native_handle_t* handle = createNativeHandle(); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 326 | handles.push_back(handle); |
| 327 | } |
| 328 | mCamera->releaseRecordingFrameHandleBatch(handles); |
| 329 | }, |
| 330 | [&]() { |
| 331 | std::vector<native_handle_t*> handles; |
| 332 | for (int8_t i = 0; |
| 333 | i < mFDP->ConsumeIntegralInRange<int8_t>(kMinElements, kMaxElements); |
| 334 | ++i) { |
Aditya Wazir | 40966bd | 2024-05-17 15:33:50 +0530 | [diff] [blame] | 335 | native_handle_t* handle = createNativeHandle(); |
Kunal Rai | f57234d | 2023-11-07 10:19:41 +0000 | [diff] [blame] | 336 | handles.push_back(handle); |
| 337 | } |
| 338 | std::vector<nsecs_t> timestamps; |
| 339 | for (int8_t i = 0; |
| 340 | i < mFDP->ConsumeIntegralInRange<int8_t>(kMinElements, kMaxElements); |
| 341 | ++i) { |
| 342 | timestamps.push_back(mFDP->ConsumeIntegral<int64_t>()); |
| 343 | } |
| 344 | mCamera->recordingFrameHandleCallbackTimestampBatch(timestamps, handles); |
| 345 | }, |
| 346 | }); |
| 347 | callCameraAPIs(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 348 | } |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | void CameraFuzzer::process(const uint8_t* data, size_t size) { |
| 352 | mFDP = new FuzzedDataProvider(data, size); |
| 353 | invokeCamera(); |
Aditya Wazir | d16f5df | 2021-07-28 17:57:32 +0530 | [diff] [blame] | 354 | delete mFDP; |
| 355 | } |
| 356 | |
| 357 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 358 | sp<CameraFuzzer> cameraFuzzer = new CameraFuzzer(); |
| 359 | cameraFuzzer->process(data, size); |
| 360 | cameraFuzzer.clear(); |
| 361 | return 0; |
| 362 | } |