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
16 #include "drawingtextadapter_fuzzer.h"
17 #include "ohos_drawing_text_adapter_impl.h"
18
19 using namespace OHOS::NWeb;
20 namespace OHOS {
DrawingTextFontAdapterFuzzTest(const uint8_t * data,size_t size)21 bool DrawingTextFontAdapterFuzzTest(const uint8_t* data, size_t size)
22 {
23 if ((data == nullptr) || (size == 0)) {
24 return false;
25 }
26
27 size_t callCount = data[0] % 10;
28 for (size_t i = 0; i < callCount; ++i) {
29 OhosDrawingTextFontAdapter &adapter = OhosDrawingTextFontAdapterImpl::GetInstance();
30 void* drawingArray = nullptr;
31 void* drawingString = nullptr;
32 void* drawingFontDescriptor = nullptr;
33 const void* drawString = nullptr;
34
35 adapter.GetSystemFontFullNamesByType(i, &drawingArray);
36 adapter.GetFontDescriptorByFullName(drawingString, i, &drawingFontDescriptor);
37 adapter.GetSystemFontFullNameByIndex(drawingArray, i, &drawString);
38 adapter.DestroyFontDescriptor(drawingFontDescriptor);
39 adapter.DestroySystemFontFullNames(drawingArray);
40 }
41 return true;
42 }
43
DrawingTextTypographyAdapterFuzzTest(const uint8_t * data,size_t size)44 bool DrawingTextTypographyAdapterFuzzTest(const uint8_t* data, size_t size)
45 {
46 if ((data == nullptr) || (size == 0)) {
47 return false;
48 }
49
50 size_t callCount = data[0] % 10;
51 for (size_t i = 0; i < callCount; ++i) {
52 OhosDrawingTextTypographyAdapter &adapter = OhosDrawingTextTypographyAdapterImpl::GetInstance();
53 void* fontConfigInfoErrorCode = nullptr;
54 void* fontConfigInfo = nullptr;
55 void* drawingArray = nullptr;
56 int32_t testNum = i;
57
58 adapter.GetSystemFontConfigInfo(fontConfigInfoErrorCode, &fontConfigInfo);
59 adapter.GetDrawingArraySize(drawingArray, testNum);
60 adapter.DestroySystemFontConfigInfo(fontConfigInfo);
61 }
62 return true;
63 }
64 } // namespace OHOS
65
66
67 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)68 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
69 {
70 /* Run your code on data */
71 OHOS::DrawingTextFontAdapterFuzzTest(data, size);
72 OHOS::DrawingTextTypographyAdapterFuzzTest(data, size);
73 return 0;
74 }
75