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 #include "light_scan_session_fuzzer.h"
16 #include "camera_log.h"
17 #include "message_parcel.h"
18 #include "securec.h"
19 #include <memory>
20 #include "timer/camera_deferred_timer.h"
21 #include "input/camera_manager.h"
22 #include "input/camera_manager_for_sys.h"
23 #include "system_ability_definition.h"
24 #include "iservice_registry.h"
25
26 namespace OHOS {
27 namespace CameraStandard {
28 static constexpr int32_t MIN_SIZE_NUM = 8;
29 sptr<LightPaintingSession> LightScanSessionFuzzer::fuzzLight_{nullptr};
30 sptr<ScanSession> LightScanSessionFuzzer::fuzzScan_{nullptr};
31
32 sptr<CameraManager> cameraManager = CameraManager::GetInstance();
LightPaintingSessionFuzzTest(FuzzedDataProvider & fdp)33 void LightScanSessionFuzzer::LightPaintingSessionFuzzTest(FuzzedDataProvider& fdp)
34 {
35 if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
36 return;
37 }
38 sptr<CameraManager> cameraManager = CameraManager::GetInstance();
39 sptr<CaptureSessionForSys> captureSessionForSys =
40 CameraManagerForSys::GetInstance()->CreateCaptureSessionForSys(SceneMode::SLOW_MOTION);
41 auto lightPaintingSession = static_cast<LightPaintingSession*>(captureSessionForSys.GetRefPtr());
42 fuzzLight_ = lightPaintingSession;
43 CHECK_RETURN_ELOG(!fuzzLight_, "Create fuzzLight_ Error");
44
45 std::vector<LightPaintingType> supportedType;
46 fuzzLight_->GetSupportedLightPaintings(supportedType);
47 LightPaintingType setType = LightPaintingType::LIGHT;
48 fuzzLight_->GetLightPainting(setType);
49 fuzzLight_->SetLightPainting(setType);
50 fuzzLight_->TriggerLighting();
51 }
ScanSessionFuzzTest(FuzzedDataProvider & fdp)52 void LightScanSessionFuzzer::ScanSessionFuzzTest(FuzzedDataProvider& fdp)
53 {
54 sptr<CameraManager> cameraManager = CameraManager::GetInstance();
55 sptr<CaptureSession> captureSession = cameraManager->CreateCaptureSession(SceneMode::SCAN);
56 sptr<ScanSession> scanSession = static_cast<ScanSession*>(captureSession.GetRefPtr());
57 fuzzScan_ = scanSession;
58 CHECK_RETURN_ELOG(!fuzzScan_, "Create fuzzScan_ Error");
59 fuzzScan_->BeginConfig();
60 sptr<CaptureOutput> preview = nullptr;
61 fuzzScan_->AddOutput(preview);
62 fuzzScan_->IsBrightnessStatusSupported();
63 fuzzScan_->UnRegisterBrightnessStatusCallback();
64 }
65
Test(uint8_t * data,size_t size)66 void Test(uint8_t* data, size_t size)
67 {
68 FuzzedDataProvider fdp(data, size);
69 auto lightscansession = std::make_unique<LightScanSessionFuzzer>();
70 if (lightscansession == nullptr) {
71 MEDIA_INFO_LOG("lightscansession is null");
72 return;
73 }
74 if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
75 return;
76 }
77 MEDIA_INFO_LOG("yuanwp_fuzz 001");
78 lightscansession->LightPaintingSessionFuzzTest(fdp);
79 lightscansession->ScanSessionFuzzTest(fdp);
80 }
81
82 } // namespace CameraStandard
83 } // namespace OHOS
84
85 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)86 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
87 {
88 OHOS::CameraStandard::Test(data, size);
89 return 0;
90 }