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 "stream_depth_data_proxy_fuzzer.h"
17 #include "camera_log.h"
18 #include "iconsumer_surface.h"
19 #include "securec.h"
20 #include "system_ability_definition.h"
21 #include "iservice_registry.h"
22 #include "output/depth_data_output.h"
23
24 namespace OHOS {
25 namespace CameraStandard {
26 const size_t THRESHOLD = 10;
27 std::shared_ptr<StreamDepthDataProxy> StreamDepthDataProxyFuzz::fuzz_{nullptr};
28
StreamDepthDataProxyTest()29 void StreamDepthDataProxyFuzz::StreamDepthDataProxyTest()
30 {
31 auto mgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
32 CHECK_RETURN_ELOG(!mgr, "samgr nullptr");
33 auto object = mgr->GetSystemAbility(CAMERA_SERVICE_ID);
34 CHECK_RETURN_ELOG(!object, "object nullptr");
35 fuzz_ = std::make_shared<StreamDepthDataProxy>(object);
36 CHECK_RETURN_ELOG(!fuzz_, "fuzz_ nullptr");
37 sptr<IStreamDepthDataCallback> callbackFunc = new (std::nothrow)DepthDataOutputCallbackImpl();
38 fuzz_->SetCallback(callbackFunc);
39 fuzz_->UnSetCallback();
40 }
41
FuzzTest(const uint8_t * rawData,size_t size)42 void FuzzTest(const uint8_t *rawData, size_t size)
43 {
44 FuzzedDataProvider fdp(rawData, size);
45 auto streamDepthDataProxy = std::make_unique<StreamDepthDataProxyFuzz>();
46 if (streamDepthDataProxy == nullptr) {
47 MEDIA_INFO_LOG("streamDepthDataProxy is null");
48 return;
49 }
50 streamDepthDataProxy->StreamDepthDataProxyTest();
51 }
52 } // namespace CameraStandard
53 } // namespace OHOS
54
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
57 {
58 if (size < OHOS::CameraStandard::THRESHOLD) {
59 return 0;
60 }
61
62 OHOS::CameraStandard::FuzzTest(data, size);
63 return 0;
64 }