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 <iostream>
17 #include "aw_common.h"
18 #include "string_ex.h"
19 #include "media_errors.h"
20 #include "directory_ex.h"
21 #include "window_option.h"
22 #include "avmetadatafile_fuzzer.h"
23
24 using namespace std;
25 using namespace OHOS;
26 using namespace Media;
27 using namespace PlayerTestParam;
28
29 namespace OHOS {
30 namespace Media {
AVMetadataFileFuzzer()31 AVMetadataFileFuzzer::AVMetadataFileFuzzer()
32 {
33 }
34
~AVMetadataFileFuzzer()35 AVMetadataFileFuzzer::~AVMetadataFileFuzzer()
36 {
37 }
38
FuzzAVMetadataFile(uint8_t * data,size_t size)39 bool AVMetadataFileFuzzer::FuzzAVMetadataFile(uint8_t *data, size_t size)
40 {
41 avmetadata = OHOS::Media::AVMetadataHelperFactory::CreateAVMetadataHelper();
42 if (avmetadata == nullptr) {
43 avmetadata->Release();
44 return false;
45 }
46
47 const string path = "/data/test/media/fuzztest.mp4";
48
49 int32_t retWritefile = WriteDataToFile(path, data, size);
50 if (retWritefile != 0) {
51 avmetadata->Release();
52 return false;
53 }
54
55 int32_t retMetadatasetsource = MetaDataSetSource(path);
56 if (retMetadatasetsource != 0) {
57 avmetadata->Release();
58 return true;
59 }
60
61 std::unordered_map<int32_t, std::string> retresolve = avmetadata->ResolveMetadata();
62 if (retresolve.empty()) {
63 avmetadata->Release();
64 return true;
65 }
66
67 std::shared_ptr<AVSharedMemory> retFetchartpicture = avmetadata->FetchArtPicture();
68 if (retFetchartpicture == nullptr) {
69 avmetadata->Release();
70 return true;
71 }
72
73 avmetadata->Release();
74 return true;
75 }
76 }
77
FuzzTestavMetadataFile(uint8_t * data,size_t size)78 bool FuzzTestavMetadataFile(uint8_t *data, size_t size)
79 {
80 if (data == nullptr) {
81 return 0;
82 }
83 AVMetadataFileFuzzer metadata;
84 return metadata.FuzzAVMetadataFile(data, size);
85 }
86 }
87
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
90 {
91 /* Run your code on data */
92 OHOS::FuzzTestavMetadataFile(data, size);
93 return 0;
94 }