1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "surfaceutils_fuzzer.h"
17
18 #include <securec.h>
19
20 #include "data_generate.h"
21 #include "iconsumer_surface.h"
22 #include "surface.h"
23 #include "surface_utils.h"
24
25 using namespace g_fuzzCommon;
26 namespace OHOS {
27 namespace {
28 constexpr uint32_t MATRIX_SIZE = 16;
29 }
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)30 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
31 {
32 if (data == nullptr) {
33 return false;
34 }
35
36 // initialize
37 g_data = data;
38 g_size = size;
39 g_pos = 0;
40
41 // get data
42 uint64_t uniqueId1 = GetData<uint64_t>();
43 uint64_t uniqueId2 = GetData<uint64_t>();
44 uint64_t uniqueId3 = GetData<uint64_t>();
45
46 // test
47 sptr<OHOS::IConsumerSurface> cSurface = OHOS::IConsumerSurface::Create();
48 sptr<OHOS::IBufferProducer> producer = cSurface->GetProducer();
49 sptr<OHOS::Surface> pSurface = Surface::CreateSurfaceAsProducer(producer);
50 SurfaceUtils* utils = SurfaceUtils::GetInstance();
51 sptr<OHOS::Surface> surface = utils->GetSurface(uniqueId1);
52 utils->Add(uniqueId1, surface);
53 utils->Add(uniqueId2, pSurface);
54 utils->Remove(uniqueId3);
55 GraphicTransformType transformType = GetData<GraphicTransformType>();
56 float matrix[MATRIX_SIZE];
57 for (int i = 0; i < MATRIX_SIZE; i++) {
58 matrix[i] = GetData<float>();
59 }
60 uint32_t matrixSize = GetData<uint32_t>();
61 Rect crop = GetData<Rect>();
62 sptr<SurfaceBuffer> buffer = SurfaceBuffer::Create();
63 utils->ComputeTransformMatrix(matrix, matrixSize, buffer, transformType, crop);
64 utils->GetNativeWindow(uniqueId1);
65 return true;
66 }
67 } // namespace OHOS
68
69 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)70 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
71 {
72 /* Run your code on data */
73 OHOS::DoSomethingInterestingWithMyAPI(data, size);
74 return 0;
75 }
76
77