1 /*
2 * Copyright (c) 2025 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 #include "get_object.h"
16 #include "ge_external_dynamic_loader.h"
17 #include "ge_external_dynamic_loader_fuzz.h"
18 #include "ge_shader_filter.h"
19 #include "ge_visual_effect_impl.h"
20
21 #include <fuzzer/FuzzedDataProvider.h>
22
23 namespace OHOS {
24 namespace GraphicsEffectEngine {
25
26 using namespace Rosen;
27
GEExternalDynamicLoaderFuzzTest001(const uint8_t * data,size_t size)28 bool GEExternalDynamicLoaderFuzzTest001(const uint8_t *data, size_t size)
29 {
30 if (data == nullptr) {
31 return false;
32 }
33 // initialize
34 GETest::g_data = data;
35 GETest::g_size = size;
36 GETest::g_pos = 0;
37
38 auto& dynamicLoader = GEExternalDynamicLoader::GetInstance();
39 auto type = (uint32_t)Drawing::GEVisualEffectImpl::FilterType::NONE;
40 uint32_t len = GETest::GetPlainData<uint32_t>();
41 uint8_t* param = (uint8_t*)(data + GETest::g_pos);
42 auto object = dynamicLoader.CreateGEXObjectByType(type, len, param);
43 if (object) {
44 delete (GEShaderFilter*)object;
45 }
46 return true;
47 }
48
49 } // namespace GraphicsEffectEngine
50 } // namespace OHOS
51
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
54 {
55 /* Run your code on data */
56 OHOS::GraphicsEffectEngine::GEExternalDynamicLoaderFuzzTest001(data, size);
57 return 0;
58 }
59