• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <cstring>
17 #include "ge_visual_effect_fuzzer.h"
18 #include "get_object.h"
19 #include "ge_render.h"
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 
26 namespace {
27 constexpr size_t STR_LEN = 10;
28 }
29 
GEVisualEffectFuzzTest001(const uint8_t * data,size_t size)30 std::shared_ptr<GEVisualEffectImpl> GEVisualEffectFuzzTest001(const uint8_t* data, size_t size)
31 {
32     if (data == nullptr) {
33         return nullptr;
34     }
35     // initialize
36     GETest::g_data = data;
37     GETest::g_size = size;
38     GETest::g_pos = 0;
39 
40     int32_t nameLen = GETest::GetPlainData<int32_t>();
41     std::string name = GETest::GetStringFromData(nameLen);
42     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
43     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
44     geVisualEffect->GetName();
45     auto impl = geVisualEffect->GetImpl();
46     return impl;
47 }
48 
GEVisualEffectFuzzTest002(const uint8_t * data,size_t size)49 std::shared_ptr<GEVisualEffect> GEVisualEffectFuzzTest002(const uint8_t* data, size_t size)
50 {
51     if (data == nullptr) {
52         return nullptr;
53     }
54     // initialize
55     GETest::g_data = data;
56     GETest::g_size = size;
57     GETest::g_pos = 0;
58 
59     int32_t nameLen = GETest::GetPlainData<int32_t>();
60     std::string name = GETest::GetStringFromData(nameLen);
61     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
62     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
63     return geVisualEffect;
64 }
65 
GEVisualEffectFuzzTest003(const uint8_t * data,size_t size)66 bool GEVisualEffectFuzzTest003(const uint8_t* data, size_t size)
67 {
68     if (data == nullptr) {
69         return false;
70     }
71     FuzzedDataProvider fdp(data, size);
72     auto geVisualEffect = std::make_shared<GEVisualEffect>("test");
73     std::string tag = fdp.ConsumeRandomLengthString(STR_LEN);
74     int32_t param = fdp.ConsumeIntegral<int32_t>();
75     geVisualEffect->SetParam(tag, param);
76     return true;
77 }
78 
GEVisualEffectFuzzTest004(const uint8_t * data,size_t size)79 bool GEVisualEffectFuzzTest004(const uint8_t* data, size_t size)
80 {
81     if (data == nullptr) {
82         return false;
83     }
84     // initialize
85     GETest::g_data = data;
86     GETest::g_size = size;
87     GETest::g_pos = 0;
88 
89     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
90     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
91     std::string tag = GETest::GetStringFromData(STR_LEN);
92     int64_t param = GETest::GetPlainData<int64_t>();
93     geVisualEffect->SetParam(tag, param);
94     return true;
95 }
96 
GEVisualEffectFuzzTest005(const uint8_t * data,size_t size)97 bool GEVisualEffectFuzzTest005(const uint8_t* data, size_t size)
98 {
99     if (data == nullptr) {
100         return false;
101     }
102     // initialize
103     GETest::g_data = data;
104     GETest::g_size = size;
105     GETest::g_pos = 0;
106 
107     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
108     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
109     std::string tag = GETest::GetStringFromData(STR_LEN);
110     float param = GETest::GetPlainData<float>();
111     geVisualEffect->SetParam(tag, param);
112     return true;
113 }
114 
GEVisualEffectFuzzTest006(const uint8_t * data,size_t size)115 bool GEVisualEffectFuzzTest006(const uint8_t* data, size_t size)
116 {
117     if (data == nullptr) {
118         return false;
119     }
120     // initialize
121     GETest::g_data = data;
122     GETest::g_size = size;
123     GETest::g_pos = 0;
124 
125     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
126     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
127     std::string tag = GETest::GetStringFromData(STR_LEN);
128     double param = GETest::GetPlainData<double>();
129     geVisualEffect->SetParam(tag, param);
130     return true;
131 }
132 
GEVisualEffectFuzzTest007(const uint8_t * data,size_t size)133 bool GEVisualEffectFuzzTest007(const uint8_t* data, size_t size)
134 {
135     if (data == nullptr) {
136         return false;
137     }
138     // initialize
139     GETest::g_data = data;
140     GETest::g_size = size;
141     GETest::g_pos = 0;
142 
143     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
144     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
145     std::string tag = GETest::GetStringFromData(STR_LEN);
146     std::string param_str = GETest::GetStringFromData(STR_LEN);
147     geVisualEffect->SetParam(tag, param_str.c_str());
148     return true;
149 }
150 
GEVisualEffectFuzzTest008(const uint8_t * data,size_t size)151 bool GEVisualEffectFuzzTest008(const uint8_t* data, size_t size)
152 {
153     if (data == nullptr) {
154         return false;
155     }
156     // initialize
157     GETest::g_data = data;
158     GETest::g_size = size;
159     GETest::g_pos = 0;
160 
161     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
162     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
163     std::string tag = GETest::GetStringFromData(STR_LEN);
164     Matrix param;
165     geVisualEffect->SetParam(tag, param);
166     return true;
167 }
168 
GEVisualEffectFuzzTest009(const uint8_t * data,size_t size)169 bool GEVisualEffectFuzzTest009(const uint8_t* data, size_t size)
170 {
171     if (data == nullptr) {
172         return false;
173     }
174     // initialize
175     GETest::g_data = data;
176     GETest::g_size = size;
177     GETest::g_pos = 0;
178 
179     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
180     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
181     std::string tag = GETest::GetStringFromData(STR_LEN);
182     float f1 = GETest::GetPlainData<float>();
183     float f2 = GETest::GetPlainData<float>();
184     std::vector<std::pair<float, float>> param {{f1, f2}};
185     geVisualEffect->SetParam(tag, param);
186     return true;
187 }
188 
GEVisualEffectFuzzTest010(const uint8_t * data,size_t size)189 bool GEVisualEffectFuzzTest010(const uint8_t* data, size_t size)
190 {
191     if (data == nullptr) {
192         return false;
193     }
194     // initialize
195     GETest::g_data = data;
196     GETest::g_size = size;
197     GETest::g_pos = 0;
198 
199     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
200     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
201     std::string tag = GETest::GetStringFromData(STR_LEN);
202     bool param = GETest::GetPlainData<bool>();
203     geVisualEffect->SetParam(tag, param);
204     return true;
205 }
206 
GEVisualEffectFuzzTest011(const uint8_t * data,size_t size)207 bool GEVisualEffectFuzzTest011(const uint8_t* data, size_t size)
208 {
209     if (data == nullptr) {
210         return false;
211     }
212     // initialize
213     GETest::g_data = data;
214     GETest::g_size = size;
215     GETest::g_pos = 0;
216 
217     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
218     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
219     std::string tag = GETest::GetStringFromData(STR_LEN);
220     uint32_t param = GETest::GetPlainData<uint32_t>();
221     geVisualEffect->SetParam(tag, param);
222     return true;
223 }
224 
GEVisualEffectFuzzTest012(const uint8_t * data,size_t size)225 bool GEVisualEffectFuzzTest012(const uint8_t* data, size_t size)
226 {
227     if (data == nullptr) {
228         return false;
229     }
230     // initialize
231     GETest::g_data = data;
232     GETest::g_size = size;
233     GETest::g_pos = 0;
234 
235     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
236     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
237     std::string tag = GETest::GetStringFromData(STR_LEN);
238     std::shared_ptr<Drawing::Image> param;
239     geVisualEffect->SetParam(tag, param);
240     return true;
241 }
242 
GEVisualEffectFuzzTest013(const uint8_t * data,size_t size)243 bool GEVisualEffectFuzzTest013(const uint8_t* data, size_t size)
244 {
245     if (data == nullptr) {
246         return false;
247     }
248     // initialize
249     GETest::g_data = data;
250     GETest::g_size = size;
251     GETest::g_pos = 0;
252 
253     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
254     auto geVisualEffect = std::make_shared<GEVisualEffect>("test", type);
255     std::string tag = GETest::GetStringFromData(STR_LEN);
256     std::shared_ptr<Drawing::ColorFilter> param;
257     geVisualEffect->SetParam(tag, param);
258     return true;
259 }
260 
GEVisualEffectFuzzTest014(const uint8_t * data,size_t size)261 std::string GEVisualEffectFuzzTest014(const uint8_t* data, size_t size)
262 {
263     if (data == nullptr) {
264         return nullptr;
265     }
266     // initialize
267     GETest::g_data = data;
268     GETest::g_size = size;
269     GETest::g_pos = 0;
270 
271     int32_t nameLen = GETest::GetPlainData<int32_t>();
272     std::string name = GETest::GetStringFromData(nameLen);
273     DrawingPaintType type = GETest::GetPlainData<DrawingPaintType>();
274     auto geVisualEffect = std::make_shared<GEVisualEffect>(name, type);
275     std::string res = geVisualEffect->GetName();
276     return res;
277 }
278 
279 } // namespace Drawing
280 } // namespace Rosen
281 } // namespace OHOS
282 
283 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)284 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
285 {
286     /* Run your code on data */
287     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest001(data, size);
288     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest002(data, size);
289     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest003(data, size);
290     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest004(data, size);
291     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest005(data, size);
292     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest006(data, size);
293     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest007(data, size);
294     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest008(data, size);
295     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest009(data, size);
296     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest010(data, size);
297     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest011(data, size);
298     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest012(data, size);
299     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest013(data, size);
300     OHOS::Rosen::Drawing::GEVisualEffectFuzzTest014(data, size);
301     return 0;
302 }
303