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 <camera2/OutputConfiguration.h>
18 #include <camera2/SessionConfiguration.h>
19 #include <fuzzer/FuzzedDataProvider.h>
20 #include <gui/IGraphicBufferProducer.h>
21 #include <gui/Surface.h>
22 #include <gui/SurfaceComposerClient.h>
23 #include "camera2common.h"
24
25 using namespace std;
26 using namespace android;
27 using namespace android::hardware::camera2::params;
28
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)29 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
30 FuzzedDataProvider fdp = FuzzedDataProvider(data, size);
31
32 SessionConfiguration* sessionConfiguration = nullptr;
33
34 if (fdp.ConsumeBool()) {
35 sessionConfiguration = new SessionConfiguration();
36 } else {
37 int32_t inputWidth = fdp.ConsumeIntegral<int32_t>();
38 int32_t inputHeight = fdp.ConsumeIntegral<int32_t>();
39 int32_t inputFormat = fdp.ConsumeIntegral<int32_t>();
40 int32_t operatingMode = fdp.ConsumeIntegral<int32_t>();
41 sessionConfiguration =
42 new SessionConfiguration(inputWidth, inputHeight, inputFormat, operatingMode);
43 }
44
45 sessionConfiguration->getInputWidth();
46 sessionConfiguration->getInputHeight();
47 sessionConfiguration->getInputFormat();
48 sessionConfiguration->getOperatingMode();
49
50 OutputConfiguration* outputConfiguration = nullptr;
51
52 if (fdp.ConsumeBool()) {
53 outputConfiguration = new OutputConfiguration();
54 sessionConfiguration->addOutputConfiguration(*outputConfiguration);
55 } else {
56 sp<IGraphicBufferProducer> iGBP = nullptr;
57 sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;
58 sp<SurfaceControl> surfaceControl = composerClient->createSurface(
59 static_cast<String8>(fdp.ConsumeRandomLengthString().c_str()),
60 fdp.ConsumeIntegral<uint32_t>(), fdp.ConsumeIntegral<uint32_t>(),
61 fdp.ConsumeIntegral<int32_t>(), fdp.ConsumeIntegral<int32_t>());
62 if (surfaceControl) {
63 sp<Surface> surface = surfaceControl->getSurface();
64 iGBP = surface->getIGraphicBufferProducer();
65 surface.clear();
66 }
67 int32_t rotation = fdp.ConsumeIntegral<int32_t>();
68 string physicalCameraId = fdp.ConsumeRandomLengthString();
69 int32_t surfaceSetID = fdp.ConsumeIntegral<int32_t>();
70 bool isShared = fdp.ConsumeBool();
71 outputConfiguration =
72 new OutputConfiguration(iGBP, rotation, physicalCameraId, surfaceSetID, isShared);
73 sessionConfiguration->addOutputConfiguration(*outputConfiguration);
74 }
75
76 sessionConfiguration->getOutputConfigurations();
77 SessionConfiguration sessionConfiguration2;
78 sessionConfiguration->outputsEqual(sessionConfiguration2);
79 sessionConfiguration->outputsLessThan(sessionConfiguration2);
80 sessionConfiguration->inputIsMultiResolution();
81
82 invokeReadWriteNullParcel<SessionConfiguration>(sessionConfiguration);
83 invokeReadWriteParcel<SessionConfiguration>(sessionConfiguration);
84
85 delete sessionConfiguration;
86 delete outputConfiguration;
87 return 0;
88 }
89