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 #include "samplingoptions_fuzzer.h"
16
17 #include <cstddef>
18 #include <cstdint>
19
20 #include "get_object.h"
21
22 #include "drawing_sampling_options.h"
23 #include "drawing_types.h"
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 constexpr size_t DATA_MIN_SIZE = 2;
29 constexpr size_t SAMPLING_OPTIONS_FILTER_MODE_ENUM_SIZE = 2;
30 constexpr size_t SAMPLING_OPTIONS_MIPMAP_MODE_ENUM_SIZE = 3;
31 } // namespace
32
33 namespace Drawing {
NativeDrawingSamplingOptionsTest001(const uint8_t * data,size_t size)34 void NativeDrawingSamplingOptionsTest001(const uint8_t* data, size_t size)
35 {
36 if (data == nullptr || size < DATA_MIN_SIZE) {
37 return;
38 }
39 g_data = data;
40 g_size = size;
41 g_pos = 0;
42
43 uint32_t filterMode = GetObject<uint32_t>();
44 uint32_t mipMapMode = GetObject<uint32_t>();
45
46 OH_Drawing_SamplingOptions* samplingOptions = OH_Drawing_SamplingOptionsCreate(
47 static_cast<OH_Drawing_FilterMode>(filterMode % SAMPLING_OPTIONS_FILTER_MODE_ENUM_SIZE),
48 static_cast<OH_Drawing_MipmapMode>(mipMapMode % SAMPLING_OPTIONS_MIPMAP_MODE_ENUM_SIZE));
49
50 OH_Drawing_SamplingOptionsDestroy(samplingOptions);
51 }
52 } // namespace Drawing
53 } // namespace Rosen
54 } // namespace OHOS
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::Rosen::Drawing::NativeDrawingSamplingOptionsTest001(data, size);
61
62 return 0;
63 }
64