• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <cstddef>
16 #include <cstdint>
17 #include "native_avcodec_videoencoder.h"
18 #include "native_averrors.h"
19 #include "native_avcodec_base.h"
20 #include "native_avcapability.h"
21 #include "softvideoenc_api11_sample.h"
22 #include <fuzzer/FuzzedDataProvider.h>
23 using namespace std;
24 using namespace OHOS;
25 using namespace OHOS::Media;
26 #define FUZZ_PROJECT_NAME "softencoderapi11_fuzzer"
27 
28 namespace OHOS {
EncoderAPI11FuzzTest(const uint8_t * data,size_t size)29 bool EncoderAPI11FuzzTest(const uint8_t *data, size_t size)
30 {
31     if (size < sizeof(int32_t)) {
32         return false;
33     }
34     bool result = false;
35     VEncAPI11FuzzSample *vEncSample = new VEncAPI11FuzzSample();
36     vEncSample->fuzzData = data;
37     vEncSample->fuzzSize = size;
38     OH_AVCapability *cap = OH_AVCodec_GetCapabilityByCategory("video/avc", true, SOFTWARE);
39     string tmpCodecName = OH_AVCapability_GetName(cap);
40     int32_t ret = vEncSample->CreateVideoEncoder(tmpCodecName.c_str());
41     if (ret != 0) {
42         delete vEncSample;
43         return true;
44     }
45     vEncSample->SetVideoEncoderCallback();
46     vEncSample->ConfigureVideoEncoder();
47     vEncSample->StartVideoEncoder();
48     vEncSample->WaitForEOS();
49     delete vEncSample;
50     return result;
51 }
52 } // namespace OHOS
53 
54 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)55 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
56 {
57     /* Run your code on data */
58     OHOS::EncoderAPI11FuzzTest(data, size);
59     return 0;
60 }
61