• 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 
16 #include <cstddef>
17 #include <cstdint>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <sys/stat.h>
21 #include "securec.h"
22 
23 #include <iostream>
24 #include "demuxer_sample.h"
25 
26 
27 #define FUZZ_PROJECT_NAME "demuxervivid_fuzzer"
28 using namespace std;
29 using namespace OHOS::Media;
30 namespace OHOS {
31 const char *MP4_PATH = "/data/test/fuzz_create.mp4";
32 const int64_t EXPECT_SIZE = 4;
33 
DemuxerFuzzTest(const uint8_t * data,size_t size)34 bool DemuxerFuzzTest(const uint8_t *data, size_t size)
35 {
36     if (size < EXPECT_SIZE) {
37         return false;
38     }
39     int32_t fd = open(MP4_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
40     if (fd < 0) {
41         return false;
42     }
43     int len = write(fd, data, size);
44     if (len <= 0) {
45         close(fd);
46         return false;
47     }
48     close(fd);
49 
50     shared_ptr<DemuxerSample> demuxerSample = make_shared<DemuxerSample>();
51     demuxerSample->filePath = MP4_PATH;
52     demuxerSample->RunNormalDemuxer();
53     int ret = remove(MP4_PATH);
54     if (ret != 0) {
55         return false;
56     }
57     return true;
58 }
59 } // namespace OHOS
60 
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
63 {
64     /* Run your code on data */
65     OHOS::DemuxerFuzzTest(data, size);
66     return 0;
67 }
68