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
16 #include "yuv_info_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <securec.h>
21
22 #include "get_object.h"
23 #include "image/yuv_info.h"
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 constexpr size_t MATH_THREE = 3;
29 constexpr size_t MATH_TWO = 2;
30 } // namespace
31
32 namespace Drawing {
YuvInfoFuzzTest000(const uint8_t * data,size_t size)33 void YuvInfoFuzzTest000(const uint8_t* data, size_t size)
34 {
35 g_data = data;
36 g_size = size;
37 g_pos = 0;
38
39 int width = GetObject<int>();
40 int height = GetObject<int>();
41 uint32_t config = GetObject<uint32_t>();
42 uint32_t sampling = GetObject<uint32_t>();
43 uint32_t colorSpace = GetObject<uint32_t>();
44
45 YUVInfo yuv;
46 YUVInfo yuv1 = YUVInfo(width, height, static_cast<YUVInfo::PlaneConfig>(config % MATH_THREE),
47 static_cast<YUVInfo::SubSampling>(sampling % MATH_TWO),
48 static_cast<YUVInfo::YUVColorSpace>(colorSpace % MATH_TWO));
49 yuv1.GetWidth();
50 yuv1.GetHeight();
51 yuv1.GetConfig();
52 yuv1.GetSampling();
53 yuv1.GetColorSpace();
54 yuv.GetWidth();
55 }
56 } // namespace Drawing
57 } // namespace Rosen
58 } // namespace OHOS
59
60 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63 /* Run your code on data */
64 OHOS::Rosen::Drawing::YuvInfoFuzzTest000(data, size);
65 return 0;
66 }