• 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 "codecgetextensionIndex_fuzzer.h"
17 #include "codeccommon_fuzzer.h"
18 #include <fuzzer/FuzzedDataProvider.h>
19 #include <securec.h>
20 
21 namespace OHOS {
22 namespace Codec {
CodecGetExtensionIndex(const uint8_t * data,size_t size)23     bool CodecGetExtensionIndex(const uint8_t *data, size_t size)
24     {
25         FuzzedDataProvider fdp(const_cast<uint8_t *>(data), size);
26         uint32_t* indexType = nullptr;
27         std::string paramName = fdp.ConsumeRandomLengthString();
28         bool result = Preconditions();
29         if (!result) {
30             HDF_LOGE("%{public}s: Preconditions failed\n", __func__);
31             return false;
32         }
33 
34         int32_t ret = g_component->GetExtensionIndex(g_component, paramName.c_str(), indexType);
35         if (ret != HDF_SUCCESS) {
36             HDF_LOGE("%{public}s: GetExtensionIndex failed, ret is [%{public}x]\n", __func__, ret);
37         }
38 
39         result = Destroy();
40         if (!result) {
41             HDF_LOGE("%{public}s: Destroy failed\n", __func__);
42             return false;
43         }
44 
45         return true;
46     }
47 } // namespace codec
48 } // namespace OHOS
49 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)50 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
51 {
52     OHOS::Codec::CodecGetExtensionIndex(data, size);
53     return 0;
54 }