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 "ohosimagedecoder_fuzzer.h"
17
18 #include <securec.h>
19 #include <sys/mman.h>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #include "image_source.h"
23 #include "image_type.h"
24 #include "media_errors.h"
25 #include "ohos_adapter_helper.h"
26
27 using namespace OHOS::NWeb;
28 const std::string DEFAULT_MOUSE_DRAG_IMAGE { "/system/etc/device_status/drag_icon/Copy_Drag.svg" };
29
30 namespace OHOS {
CreateDecoderAdapter()31 std::shared_ptr<OhosImageDecoderAdapter> CreateDecoderAdapter()
32 {
33 return OhosAdapterHelper::GetInstance().CreateOhosImageDecoderAdapter();
34 }
35
GetParametersFuzzTest(const uint8_t * data,size_t size)36 bool GetParametersFuzzTest(const uint8_t* data, size_t size)
37 {
38 auto adapter = CreateDecoderAdapter();
39 if (!adapter) {
40 return false;
41 }
42 adapter->GetEncodedFormat();
43 adapter->GetImageWidth();
44 adapter->GetImageHeight();
45 adapter->GetFd();
46 adapter->GetStride();
47 adapter->GetOffset();
48 adapter->GetSize();
49 adapter->GetNativeWindowBuffer();
50 adapter->GetPlanesCount();
51 adapter->GetDecodeData();
52 adapter->ReleasePixelMap();
53 return true;
54 }
55
56 } // namespace OHOS
57
58 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
60 {
61 OHOS::GetParametersFuzzTest(data, size);
62 return 0;
63 }
64