1 /*
2 * Copyright (C) 2020 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 <vector>
18
19 #include <fuzzer/FuzzedDataProvider.h>
20
21 #include "device3/DistortionMapper.h"
22 #include <camera/CameraMetadata.h>
23
24 using namespace android;
25 using namespace android::camera3;
26 using DistortionMapperInfo = android::camera3::DistortionMapper::DistortionMapperInfo;
27
28 int32_t testActiveArray[] = {100, 100, 1000, 750};
29 float testICal[] = { 1000.f, 1000.f, 500.f, 500.f, 0.f };
30 float identityDistortion[] = { 0.f, 0.f, 0.f, 0.f, 0.f};
31
setupTestMapper(DistortionMapper * m,float distortion[5],float intrinsics[5],int32_t activeArray[4],int32_t preCorrectionActiveArray[4])32 void setupTestMapper(DistortionMapper *m,
33 float distortion[5], float intrinsics[5],
34 int32_t activeArray[4], int32_t preCorrectionActiveArray[4]) {
35 CameraMetadata deviceInfo;
36
37 deviceInfo.update(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
38 preCorrectionActiveArray, 4);
39
40 deviceInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,
41 activeArray, 4);
42
43 deviceInfo.update(ANDROID_LENS_INTRINSIC_CALIBRATION,
44 intrinsics, 5);
45
46 deviceInfo.update(ANDROID_LENS_DISTORTION,
47 distortion, 5);
48
49 m->setupStaticInfo(deviceInfo);
50 }
51
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
53 FuzzedDataProvider fdp(data, size);
54
55 DistortionMapper m;
56 setupTestMapper(&m, identityDistortion, testICal,
57 /*activeArray*/ testActiveArray,
58 /*preCorrectionActiveArray*/ testActiveArray);
59
60 bool clamp = fdp.ConsumeBool();
61 bool simple = fdp.ConsumeBool();
62 std::vector<int32_t> input;
63 for (int index = 0; fdp.remaining_bytes() > 0; index++) {
64 input.push_back(fdp.ConsumeIntegral<int32_t>());
65 }
66 DistortionMapperInfo *mapperInfo = m.getMapperInfo();
67 // The size argument counts how many coordinate pairs there are, so
68 // it is expected to be 1/2 the size of the input.
69 m.mapCorrectedToRaw(input.data(), input.size()/2, mapperInfo, clamp, simple);
70
71 return 0;
72 }
73