• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "moving_photo_surface_wrapper_fuzzer.h"
17 #include "camera_input.h"
18 #include "camera_log.h"
19 #include "camera_photo_proxy.h"
20 #include "capture_input.h"
21 #include "capture_output.h"
22 #include "capture_scene_const.h"
23 #include "input/camera_manager.h"
24 #include "message_parcel.h"
25 #include "refbase.h"
26 #include <cstddef>
27 #include <cstdint>
28 #include <memory>
29 #include "token_setproc.h"
30 #include "nativetoken_kit.h"
31 #include "accesstoken_kit.h"
32 #include "securec.h"
33 #include <mutex>
34 
35 namespace OHOS {
36 namespace CameraStandard {
37 static constexpr int32_t MIN_SIZE_NUM = 16;
38 
39 std::shared_ptr<MovingPhotoSurfaceWrapper> MovingPhotoSurfaceWrapperFuzzer::fuzz_{nullptr};
40 std::shared_ptr<MovingPhotoSurfaceWrapper::BufferConsumerListener>
41     MovingPhotoSurfaceWrapperFuzzer::listener_{nullptr};
42 
MovingPhotoSurfaceWrapperFuzzTest(FuzzedDataProvider & fdp)43 void MovingPhotoSurfaceWrapperFuzzer::MovingPhotoSurfaceWrapperFuzzTest(FuzzedDataProvider& fdp)
44 {
45     if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
46         return;
47     }
48     fuzz_ = std::make_shared<MovingPhotoSurfaceWrapper>();
49     CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
50     fuzz_->GetProducer();
51     int32_t width = fdp.ConsumeIntegral<int32_t>();
52     int32_t height = fdp.ConsumeIntegral<int32_t>();
53     fuzz_->CreateMovingPhotoSurfaceWrapper(width, height);
54     fuzz_->OnBufferArrival();
55     if (listener_ == nullptr) {
56         sptr<MovingPhotoSurfaceWrapper> surfaceWrapper = nullptr;
57         listener_ = std::make_shared<MovingPhotoSurfaceWrapper::BufferConsumerListener>(surfaceWrapper);
58     }
59     listener_->OnBufferAvailable();
60 }
61 
Test(uint8_t * data,size_t size)62 void Test(uint8_t* data, size_t size)
63 {
64     FuzzedDataProvider fdp(data, size);
65     auto movingPhotoSurfaceWrapper = std::make_unique<MovingPhotoSurfaceWrapperFuzzer>();
66     if (movingPhotoSurfaceWrapper == nullptr) {
67         MEDIA_INFO_LOG("movingPhotoSurfaceWrapper is null");
68         return;
69     }
70     movingPhotoSurfaceWrapper->MovingPhotoSurfaceWrapperFuzzTest(fdp);
71 }
72 
73 } // namespace CameraStandard
74 } // namespace OHOS
75 
76 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)77 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size)
78 {
79     OHOS::CameraStandard::Test(data, size);
80     return 0;
81 }