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 "camera_report_dfx_utils_fuzzer.h"
17 #include "camera_log.h"
18 #include "message_parcel.h"
19 #include "securec.h"
20 #include <mutex>
21
22 namespace OHOS {
23 namespace CameraStandard {
24 static constexpr int32_t MIN_SIZE_NUM = 4;
25
26 std::shared_ptr<CameraReportDfxUtils> CameraReportDfxUtilsFuzzer::fuzz_{nullptr};
27
28 /*
29 * describe: get data from outside untrusted data(g_data) which size is according to sizeof(T)
30 * tips: only support basic type
31 */
CameraReportDfxUtilsFuzzTest(FuzzedDataProvider & fdp)32 void CameraReportDfxUtilsFuzzer::CameraReportDfxUtilsFuzzTest(FuzzedDataProvider& fdp)
33 {
34 fuzz_ = std::make_shared<CameraReportDfxUtils>();
35 CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
36 int32_t captureId = fdp.ConsumeIntegral<int32_t>();
37 fuzz_->SetFirstBufferEndInfo(captureId);
38 fuzz_->SetPrepareProxyStartInfo(captureId);
39 fuzz_->SetAddProxyEndInfo(captureId);
40 fuzz_->SetAddProxyStartInfo(captureId);
41 fuzz_->SetAddProxyEndInfo(captureId);
42 CaptureDfxInfo captureInfo;
43 fuzz_->ReportPerformanceDeferredPhoto(captureInfo);
44 }
45
Test(uint8_t * data,size_t size)46 void Test(uint8_t* data, size_t size)
47 {
48 auto cameraReportDfxUtils = std::make_unique<CameraReportDfxUtilsFuzzer>();
49 if (cameraReportDfxUtils == nullptr) {
50 MEDIA_INFO_LOG("cameraReportDfxUtils is null");
51 return;
52 }
53 FuzzedDataProvider fdp(data, size);
54 if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
55 return;
56 }
57 cameraReportDfxUtils->CameraReportDfxUtilsFuzzTest(fdp);
58 }
59 } // namespace CameraStandard
60 } // namespace OHOS
61
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
64 {
65 OHOS::CameraStandard::Test(data, size);
66 return 0;
67 }