• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "pointer_style.h"
17 #include "cursorpixelmap_fuzzer.h"
18 #include "image_source.h"
19 #include "mmi_log.h"
20 
21 #include "securec.h"
22 
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "CursorPixelMapFuzzTest"
25 
26 namespace OHOS {
27 namespace MMI {
28 constexpr int32_t MOUSE_ICON_SIZE = 64;
SetMouseIconTest(const std::string iconPath)29 std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath)
30 {
31     OHOS::Media::SourceOptions opts;
32     opts.formatHint = "image/svg+xml";
33     uint32_t ret = 0;
34     auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
35     CHKPP(imageSource);
36     std::set<std::string> formats;
37     ret = imageSource->GetSupportedFormats(formats);
38     MMI_HILOGD("Get supported format ret:%{public}u", ret);
39 
40     OHOS::Media::DecodeOptions decodeOpts;
41     decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
42 
43     std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
44     CHKPL(pixelMap);
45     return pixelMap;
46 }
47 
CursorPixelMapFuzzTest(const uint8_t * data,size_t size)48 bool CursorPixelMapFuzzTest(const uint8_t *data, size_t size)
49 {
50     const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
51     CursorPixelMap cursorPixelmap;
52     cursorPixelmap.pixelMap = (void *)SetMouseIconTest(iconPath).get();
53 
54     Parcel parcel;
55     cursorPixelmap.Marshalling(parcel);
56     cursorPixelmap.ReadFromParcel(parcel);
57     cursorPixelmap.Unmarshalling(parcel);
58     MMI_HILOGD("CursorPixelMapFuzzTest");
59     return true;
60 }
61 } // MMI
62 } // OHOS
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
66 {
67     /* Run your code on data */
68     if (data == nullptr) {
69         return 0;
70     }
71 
72     OHOS::MMI::CursorPixelMapFuzzTest(data, size);
73     return 0;
74 }
75