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 "codecgetextensionIndex_fuzzer.h"
17 #include "codeccommon_fuzzer.h"
18
19 #include <securec.h>
20
21 struct AllParameters {
22 char *paramName;
23 uint32_t *indexType;
24 };
25
26 namespace OHOS {
27 namespace Codec {
CodecGetExtensionIndex(const uint8_t * data,size_t size)28 bool CodecGetExtensionIndex(const uint8_t *data, size_t size)
29 {
30 struct AllParameters params;
31 if (data == nullptr) {
32 HDF_LOGE("%{public}s: data is nullptr", __func__);
33 return false;
34 }
35
36 if (memcpy_s(reinterpret_cast<void *>(¶ms), sizeof(params), data, sizeof(params)) != 0) {
37 HDF_LOGE("%{public}s: memcpy_s failed", __func__);
38 return false;
39 }
40
41 bool result = Preconditions();
42 if (!result) {
43 HDF_LOGE("%{public}s: Preconditions failed", __func__);
44 return false;
45 }
46
47 int32_t ret = g_component->GetExtensionIndex(g_component, params.paramName, params.indexType);
48 if (ret != HDF_SUCCESS) {
49 HDF_LOGE("%{public}s: GetExtensionIndex failed", __func__);
50 }
51
52 result = Destroy();
53 if (!result) {
54 HDF_LOGE("%{public}s: Destroy failed", __func__);
55 }
56
57 return (result && ret == HDF_SUCCESS);
58 }
59 } // namespace Codec
60 } // namespace OHOS
61
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
63 {
64 OHOS::Codec::CodecGetExtensionIndex(data, size);
65 return 0;
66 }
67