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