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 "codeccreatecomponent_fuzzer.h"
17 #include "codeccommon_fuzzer.h"
18
19 namespace OHOS {
20 namespace Codec {
CodecCreateComponent(const uint8_t * data,size_t size)21 bool CodecCreateComponent(const uint8_t* data, size_t size)
22 {
23 bool result = false;
24 struct CodecComponentManager *manager = nullptr;
25 struct CodecComponentType *component = nullptr;
26 CodecCallbackType* callback = CodecCallbackTypeStubGetInstance();
27
28 manager = GetCodecComponentManager();
29 if (manager == nullptr) {
30 HDF_LOGE("%{public}s: GetCodecComponentManager failed\n", __func__);
31 return false;
32 }
33
34 int32_t ret = manager->CreateComponent(&component, &componentId, (char*)data, *(int64_t *)data, callback);
35 if (ret == HDF_SUCCESS) {
36 HDF_LOGI("%{public}s: CreateComponent succeed\n", __func__);
37 result = true;
38 }
39
40 ret = manager->DestroyComponent(componentId);
41 if (ret != HDF_SUCCESS) {
42 HDF_LOGE("%{public}s: DestroyComponent failed\n", __func__);
43 return false;
44 }
45 CodecComponentTypeRelease(component);
46 CodecComponentManagerRelease();
47
48 return result;
49 }
50 } // namespace codec
51 } // namespace OHOS
52
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55 OHOS::Codec::CodecCreateComponent(data, size);
56 return 0;
57 }