• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <cstddef>
17 #include <cstdint>
18 #include "native_avcodec_base.h"
19 #include "native_avcodec_videodecoder.h"
20 #include "native_averrors.h"
21 #include "videodec_ndk_sample.h"
22 
23 #define FUZZ_PROJECT_NAME "swdecoderResource_fuzzer"
24 
25 using namespace std;
26 using namespace OHOS;
27 using namespace OHOS::Media;
28 
29 static VDecNdkSample *vDecSample = nullptr;
30 constexpr uint32_t DEFAULT_WIDTH = 1920;
31 constexpr uint32_t DEFAULT_HEIGHT = 1080;
32 constexpr double DEFAULT_FRAME_RATE = 30.0;
33 
34 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)35 bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
36 {
37     if (!vDecSample) {
38         vDecSample = new VDecNdkSample();
39         vDecSample->DEFAULT_WIDTH = DEFAULT_WIDTH;
40         vDecSample->DEFAULT_HEIGHT = DEFAULT_HEIGHT;
41         vDecSample->DEFAULT_FRAME_RATE = DEFAULT_FRAME_RATE;
42         vDecSample->SURFACE_OUTPUT = false;
43         vDecSample->CreateVideoDecoder("OH.Media.Codec.Decoder.Video.AVC");
44         vDecSample->ConfigureVideoDecoder();
45         vDecSample->SetVideoDecoderCallback();
46         vDecSample->Start();
47     }
48     OH_AVErrCode ret = vDecSample->InputFunc_FUZZ(data, size);
49     if (ret != AV_ERR_OK) {
50         vDecSample->Release();
51         delete vDecSample;
52         vDecSample = nullptr;
53         return false;
54     }
55     return true;
56 }
57 } // namespace OHOS
58 
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
61 {
62     /* Run your code on data */
63     OHOS::DoSomethingInterestingWithMyAPI(data, size);
64     return 0;
65 }
66