• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "avmetadatafetchframeattime_fuzzer.h"
17 #include <iostream>
18 #include "aw_common.h"
19 #include "string_ex.h"
20 #include "media_errors.h"
21 #include "directory_ex.h"
22 #include "window_option.h"
23 #include "image_type.h"
24 
25 
26 using namespace std;
27 using namespace OHOS;
28 using namespace Media;
29 using namespace PlayerTestParam;
30 
31 namespace OHOS {
32 namespace Media {
AVMetadataFetchFrameAtTimeFuzzer()33 AVMetadataFetchFrameAtTimeFuzzer::AVMetadataFetchFrameAtTimeFuzzer()
34 {
35 }
36 
~AVMetadataFetchFrameAtTimeFuzzer()37 AVMetadataFetchFrameAtTimeFuzzer::~AVMetadataFetchFrameAtTimeFuzzer()
38 {
39 }
40 
FuzzAVMetadataFetchFrameAtTime(uint8_t * data,size_t size)41 bool AVMetadataFetchFrameAtTimeFuzzer::FuzzAVMetadataFetchFrameAtTime(uint8_t *data, size_t size)
42 {
43     constexpr int32_t AV_METADATA_QUERY_OPTION_LIST = 4;
44     constexpr int32_t AV_COLOR_FORMAT_LIST = 11;
45 
46     avmetadata = AVMetadataHelperFactory::CreateAVMetadataHelper();
47     if (avmetadata == nullptr) {
48         avmetadata->Release();
49         return false;
50     }
51 
52     const string path = "/data/test/media/H264_AAC.mp4";
53     if (MetaDataSetSource(path) != 0) {
54         avmetadata->Release();
55         return false;
56     }
57 
58     int32_t avMetadataQueryOption[AV_METADATA_QUERY_OPTION_LIST] {
59         AV_META_QUERY_NEXT_SYNC,
60         AV_META_QUERY_PREVIOUS_SYNC,
61         AV_META_QUERY_CLOSEST_SYNC,
62         AV_META_QUERY_CLOSEST
63     };
64 
65     int32_t option = avMetadataQueryOption[ProduceRandomNumberCrypt() % AV_METADATA_QUERY_OPTION_LIST];
66     PixelFormat colorFormats[AV_COLOR_FORMAT_LIST] {
67         PixelFormat::UNKNOWN,
68         PixelFormat::ARGB_8888,
69         PixelFormat::RGB_565,
70         PixelFormat::RGBA_8888,
71         PixelFormat::BGRA_8888,
72         PixelFormat::RGB_888,
73         PixelFormat::ALPHA_8,
74         PixelFormat::RGBA_F16,
75         PixelFormat::NV21,
76         PixelFormat::NV12,
77         PixelFormat::CMYK
78     };
79     PixelFormat colorFormat = colorFormats[ProduceRandomNumberCrypt() % AV_COLOR_FORMAT_LIST];
80 
81     struct PixelMapParams pixelMapParams = {ProduceRandomNumberCrypt(), ProduceRandomNumberCrypt(), colorFormat};
82 
83     std::shared_ptr<PixelMap> retFetchFrameAtTime =
84         avmetadata->FetchFrameAtTime(*reinterpret_cast<int64_t *>(data), option, pixelMapParams);
85 
86     if (retFetchFrameAtTime != 0) {
87         avmetadata->Release();
88         return true;
89     }
90     avmetadata->Release();
91     return true;
92 }
93 }
94 
FuzzTestAVMetadataFetchFrameAtTime(uint8_t * data,size_t size)95 bool FuzzTestAVMetadataFetchFrameAtTime(uint8_t *data, size_t size)
96 {
97     if (data == nullptr) {
98         return 0;
99     }
100 
101     if (size < sizeof(int64_t)) {
102         return 0;
103     }
104     AVMetadataFetchFrameAtTimeFuzzer metadata;
105     return metadata.FuzzAVMetadataFetchFrameAtTime(data, size);
106 }
107 }
108 
109 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)110 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
111 {
112     /* Run your code on data */
113     OHOS::FuzzTestAVMetadataFetchFrameAtTime(data, size);
114     return 0;
115 }
116