1 /*
2 * Copyright (c) 2023 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 "smooth_zoom_fuzzer.h"
17 #include "camera_timer.h"
18 #include "hstream_capture.h"
19 #include "message_parcel.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 #include "accesstoken_kit.h"
23 #include "camera_metadata_info.h"
24 #include "metadata_utils.h"
25 #include <fuzzer/FuzzedDataProvider.h>
26 #include "test_token.h"
27
28 namespace {
29
30 const int32_t LIMITSIZE = 12;
31
32 }
33
34 namespace OHOS {
35 namespace CameraStandard {
36
37 std::shared_ptr<SmoothZoom> SmoothZoomFuzzer::fuzz_{nullptr};
38 static constexpr int32_t MIN_SIZE_NUM = 4;
39
Test(uint8_t * rawData,size_t size)40 void SmoothZoomFuzzer::Test(uint8_t *rawData, size_t size)
41 {
42 FuzzedDataProvider fdp(rawData, size);
43 if (fdp.remaining_bytes() < MIN_SIZE_NUM) {
44 return;
45 }
46 CHECK_RETURN_ELOG(!TestToken().GetAllCameraPermission(), "GetPermission error");
47
48 fuzz_ = std::make_shared<SmoothZoom>();
49 CHECK_RETURN_ELOG(!fuzz_, "Create fuzz_ Error");
50 MessageParcel data;
51 data.WriteRawData(rawData, size);
52
53 SmoothZoomType mode = static_cast<SmoothZoomType>(fdp.ConsumeBool());
54 auto alg = fuzz_->GetZoomAlgorithm(mode);
55
56 data.RewindRead(0);
57 float currentZoom = data.ReadFloat();
58 float targetZoom = data.ReadFloat();
59 float frameInterval = data.ReadFloat();
60 alg->GetZoomArray(currentZoom, targetZoom, frameInterval);
61 }
62
63 } // namespace CameraStandard
64 } // namespace OHOS
65
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
68 {
69 /* Run your code on data */
70 OHOS::CameraStandard::SmoothZoomFuzzer::Test(data, size);
71 return 0;
72 }