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_videodecoder.h"
18 #include "native_averrors.h"
19 #include "native_avcodec_base.h"
20 #include "videodec_sample.h"
21 #include <fuzzer/FuzzedDataProvider.h>
22 using namespace std;
23 using namespace OHOS;
24 using namespace OHOS::Media;
25 #define FUZZ_PROJECT_NAME "fcodecsurfaceconfigure_fuzzer"
26 const uint32_t SURFACE_BOUND = 2;
27 const size_t EXPECT_SIZE = 6;
28
29 namespace OHOS {
FCodecSurfaceConfigureFuzzer(const uint8_t * data,size_t size)30 bool FCodecSurfaceConfigureFuzzer(const uint8_t *data, size_t size)
31 {
32 if (data == nullptr) {
33 return false;
34 }
35 if (size < EXPECT_SIZE) {
36 return false;
37 }
38 FuzzedDataProvider fdp(data, size);
39 uint32_t decision = fdp.ConsumeIntegral<uint32_t>();
40 VDecFuzzSample *vDecSample = new VDecFuzzSample();
41 if (decision % SURFACE_BOUND == 0) {
42 vDecSample->isSurfaceMode = true;
43 } else {
44 vDecSample->isSurfaceMode = false;
45 }
46 vDecSample->RunVideoDec();
47 delete vDecSample;
48 return false;
49 }
50 } // namespace OHOS
51
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
54 {
55 /* Run your code on data */
56 OHOS::FCodecSurfaceConfigureFuzzer(data, size);
57 return 0;
58 }