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