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 = true;
24 struct CodecComponentManager *manager = nullptr;
25 struct CodecComponentType *component = nullptr;
26 uint32_t componentId;
27 CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
28
29 manager = GetCodecComponentManager();
30 if (manager == nullptr) {
31 HDF_LOGE("%{public}s: GetCodecComponentManager failed", __func__);
32 return false;
33 }
34
35 int32_t ret =
36 manager->CreateComponent(&component, &componentId, reinterpret_cast<char *>(const_cast<uint8_t *>(data)),
37 *(reinterpret_cast<int64_t *>(const_cast<uint8_t *>(data))), callback);
38 if (ret != HDF_SUCCESS) {
39 HDF_LOGE("%{public}s: CreateComponent failed", __func__);
40 result = false;
41 }
42
43 ret = manager->DestroyComponent(componentId);
44 if (ret != HDF_SUCCESS) {
45 HDF_LOGE("%{public}s: DestroyComponent failed", __func__);
46 result = false;
47 }
48 CodecCallbackTypeRelease(callback);
49 CodecComponentManagerRelease();
50
51 return result;
52 }
53 } // namespace Codec
54 } // namespace OHOS
55
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
57 {
58 OHOS::Codec::CodecCreateComponent(data, size);
59 return 0;
60 }