1 /*
2 * Copyright (c) 2023 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 "codecgetcomponentcapabilitylist_fuzzer.h"
17 #include "codeccommon_fuzzer.h"
18
19 using namespace OHOS::HDI::Codec::V4_0;
20
21 namespace OHOS {
22 namespace Codec {
CodecGetComponentCapabilityList(const uint8_t * data,size_t size)23 bool CodecGetComponentCapabilityList(const uint8_t* data, size_t size)
24 {
25 if (data == nullptr) {
26 return false;
27 }
28
29 OHOS::sptr<OHOS::HDI::Codec::V4_0::ICodecComponentManager> omxMgr_ = nullptr;
30
31 omxMgr_ = ICodecComponentManager::Get(true);
32 if (omxMgr_ == nullptr) {
33 HDF_LOGE("%{public}s: ICodecComponentManager failed\n", __func__);
34 return false;
35 }
36
37 int32_t count = 0;
38 auto err = omxMgr_->GetComponentNum(count);
39 if (err != HDF_SUCCESS || count <= 0) {
40 HDF_LOGE("%{public}s GetComponentNum return %{public}d, count = %{public}d", __func__, err, count);
41 return false;
42 }
43
44 std::vector<CodecCompCapability> caps;
45 err = omxMgr_->GetComponentCapabilityList(caps,
46 static_cast<uint32_t>(*(const_cast<uint8_t *>(data))));
47 if (err != HDF_SUCCESS) {
48 HDF_LOGE("%{public}s GetComponentCapabilityList return %{public}d", __func__, err);
49 return false;
50 }
51
52 return true;
53 }
54 } // namespace codec
55 } // namespace OHOS
56
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 OHOS::Codec::CodecGetComponentCapabilityList(data, size);
60 return 0;
61 }
62