• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <CaptureResult.h>
18 #include <fuzzer/FuzzedDataProvider.h>
19 #include "camera2common.h"
20 
21 using namespace std;
22 using namespace android;
23 using namespace android::hardware::camera2::impl;
24 
25 constexpr int32_t kSizeMin = 0;
26 constexpr int32_t kSizeMax = 1000;
27 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
29     FuzzedDataProvider fdp = FuzzedDataProvider(data, size);
30     PhysicalCaptureResultInfo* physicalCaptureResultInfo = nullptr;
31 
32     if (fdp.ConsumeBool()) {
33         physicalCaptureResultInfo = new PhysicalCaptureResultInfo();
34     } else {
35         string camId = fdp.ConsumeRandomLengthString();
36         String16 cameraId(camId.c_str());
37         CameraMetadata cameraMetadata = CameraMetadata();
38         physicalCaptureResultInfo = new PhysicalCaptureResultInfo(cameraId, cameraMetadata);
39     }
40 
41     invokeReadWriteParcel<PhysicalCaptureResultInfo>(physicalCaptureResultInfo);
42 
43     CaptureResult* captureResult = new CaptureResult();
44 
45     if (fdp.ConsumeBool()) {
46         captureResult->mMetadata = CameraMetadata();
47     }
48     if (fdp.ConsumeBool()) {
49         captureResult->mResultExtras = CaptureResultExtras();
50         string errCamId = fdp.ConsumeRandomLengthString();
51         String16 errCameraId(errCamId.c_str());
52         captureResult->mResultExtras.errorPhysicalCameraId = errCameraId;
53         captureResult->mResultExtras.isValid();
54         invokeReadWriteNullParcel<CaptureResultExtras>(&(captureResult->mResultExtras));
55     }
56     if (fdp.ConsumeBool()) {
57         size_t physicalMetadatasSize = fdp.ConsumeIntegralInRange<size_t>(kSizeMin, kSizeMax);
58         for (size_t idx = 0; idx < physicalMetadatasSize; ++idx) {
59             captureResult->mPhysicalMetadatas.push_back(PhysicalCaptureResultInfo());
60         }
61     }
62 
63     invokeReadWriteNullParcel<CaptureResult>(captureResult);
64     invokeReadWriteParcel<CaptureResult>(captureResult);
65     CaptureResult captureResult2(*captureResult);
66     CaptureResult captureResult3(std::move(captureResult2));
67 
68     delete captureResult;
69     delete physicalCaptureResultInfo;
70     return 0;
71 }
72