1 /*
2 * Copyright (c) 2024 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 "dps_video_report_fuzzer.h"
17 #include "camera_log.h"
18 #include "message_parcel.h"
19 #include "securec.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
23 using namespace DeferredProcessing;
24 static constexpr int32_t MIN_SIZE_NUM = 128;
25 const size_t MAX_LENGTH_STRING = 64;
26
27 std::shared_ptr<DfxVideoReport> DfxVideoReportFuzzer::fuzz_{nullptr};
28
DfxVideoReportFuzzTest(FuzzedDataProvider & fdp)29 void DfxVideoReportFuzzer::DfxVideoReportFuzzTest(FuzzedDataProvider& fdp)
30 {
31 if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
32 return;
33 }
34 fuzz_ = std::make_shared<DfxVideoReport>();
35 CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
36 DpsCallerInfo callerInfo;
37 std::string videoId(fdp.ConsumeRandomLengthString(MAX_LENGTH_STRING));
38 callerInfo.bundleName = (fdp.ConsumeRandomLengthString(MAX_LENGTH_STRING));
39 callerInfo.version = (fdp.ConsumeRandomLengthString(MAX_LENGTH_STRING));
40 callerInfo.pid = 0;
41 callerInfo.uid = 0;
42 callerInfo.tokenID = 0;
43 DfxVideoReport::GetInstance().ReportAddVideoEvent(videoId, callerInfo);
44 int32_t pauseReason = fdp.ConsumeIntegral<int32_t>();
45 DfxVideoReport::GetInstance().ReportPauseVideoEvent(videoId, pauseReason);
46 DfxVideoReport::GetInstance().ReportResumeVideoEvent(videoId);
47 DfxVideoReport::GetInstance().ReportCompleteVideoEvent(videoId);
48 }
49
Test(uint8_t * data,size_t size)50 void Test(uint8_t* data, size_t size)
51 {
52 FuzzedDataProvider fdp(data, size);
53 auto dfxVideoReport = std::make_unique<DfxVideoReportFuzzer>();
54 if (dfxVideoReport == nullptr) {
55 MEDIA_INFO_LOG("dfxVideoReport is null");
56 return;
57 }
58 dfxVideoReport->DfxVideoReportFuzzTest(fdp);
59 }
60
61 } // namespace CameraStandard
62 } // namespace OHOS
63
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
66 {
67 OHOS::CameraStandard::Test(data, size);
68 return 0;
69 }