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 "camera_fwk_metadata_utils_fuzzer.h"
17 #include "hstream_capture.h"
18 #include "message_parcel.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21 #include "accesstoken_kit.h"
22 #include "camera_metadata_info.h"
23 #include "metadata_utils.h"
24 #include "test_token.h"
25
26 namespace {
27
28 const int32_t LIMITSIZE = 16;
29
30 }
31
32 namespace OHOS {
33 namespace CameraStandard {
34
Test(uint8_t * rawData,size_t size)35 void CameraFwkMetadataUtilsFuzzer::Test(uint8_t *rawData, size_t size)
36 {
37 CHECK_RETURN(rawData == nullptr || size < LIMITSIZE);
38 CHECK_RETURN_ELOG(!TestToken().GetAllCameraPermission(), "GetPermission error");
39 MessageParcel data;
40 data.WriteRawData(rawData, size);
41
42 std::shared_ptr<OHOS::Camera::CameraMetadata> srcMetadata;
43 std::shared_ptr<OHOS::Camera::CameraMetadata> dstMetadata;
44
45 data.RewindRead(0);
46 srcMetadata->addEntry(data.ReadUint32(), rawData, size);
47 CameraFwkMetadataUtils::MergeMetadata(srcMetadata, dstMetadata);
48
49 std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = CameraFwkMetadataUtils::CopyMetadata(srcMetadata);
50
51 CameraFwkMetadataUtils::LogFormatCameraMetadata(metadata);
52
53 CameraFwkMetadataUtils::RecreateMetadata(metadata);
54
55 data.RewindRead(0);
56 camera_metadata_item_t item = {
57 data.ReadUint32(),
58 data.ReadUint32(),
59 data.ReadUint32(),
60 data.ReadUint32(),
61 };
62 camera_metadata_item_t srcItem = item;
63
64 CameraFwkMetadataUtils::UpdateMetadataTag(srcItem, dstMetadata);
65 CameraFwkMetadataUtils::DumpMetadataItemInfo(item);
66 CameraFwkMetadataUtils::DumpMetadataInfo(srcMetadata);
67 }
68
69 } // namespace CameraStandard
70 } // namespace OHOS
71
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
74 {
75 /* Run your code on data */
76 OHOS::CameraStandard::CameraFwkMetadataUtilsFuzzer::Test(data, size);
77 return 0;
78 }