• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "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         struct CodecComponentManager *manager = nullptr;
24         struct CodecComponentType *component = nullptr;
25         CodecCallbackType* g_callback = CodecCallbackTypeStubGetInstance();
26 
27         manager = GetCodecComponentManager();
28         if (manager == nullptr) {
29             HDF_LOGE("%{public}s: GetCodecComponentManager failed\n", __func__);
30             return false;
31         }
32 
33         std::string compName("OMX.rk.video_encoder.avc");
34         int32_t ret = manager->CreateComponent(&component, &g_componentId, compName.data(),
35             static_cast<int64_t >(*data), g_callback);
36         if (ret != HDF_SUCCESS) {
37             HDF_LOGE("%{public}s: UseEglImage failed, ret is [%{public}x]\n", __func__, ret);
38         }
39 
40         int32_t result = manager->DestroyComponent(g_componentId);
41         if (result != HDF_SUCCESS) {
42             HDF_LOGE("%{public}s: DestroyComponent failed\n", __func__);
43             return false;
44         }
45         CodecComponentTypeRelease(component);
46         CodecComponentManagerRelease();
47 
48         return true;
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 }