• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "medialibrary_extension_batch_insert_fuzzer.h"
16 
17 #include <cstdint>
18 #include <string>
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 #include "data_ability_observer_interface.h"
22 #include "datashare_business_error.h"
23 #include "datashare_helper.h"
24 #include "datashare_predicates.h"
25 #include "datashare_values_bucket.h"
26 #include "media_datashare_ext_ability.h"
27 #include "media_datashare_stub_impl.h"
28 #include "media_log.h"
29 #include "runtime.h"
30 
31 namespace OHOS {
32 using namespace std;
33 using namespace AbilityRuntime;
34 using namespace DataShare;
35 static const int32_t NUM_BYTES = 1;
36 FuzzedDataProvider *provider = nullptr;
FuzzUri()37 static inline Uri FuzzUri()
38 {
39     return Uri(provider->ConsumeBytesAsString(NUM_BYTES));
40 }
41 
FuzzDataShareValuesBucket()42 static inline DataShareValuesBucket FuzzDataShareValuesBucket()
43 {
44     return {};
45 }
46 
FuzzVectorDataShareValuesBucket()47 static inline vector<DataShareValuesBucket> FuzzVectorDataShareValuesBucket()
48 {
49     return {FuzzDataShareValuesBucket()};
50 }
51 
BatchInsertFuzzer(MediaDataShareExtAbility & extension)52 static inline void BatchInsertFuzzer(MediaDataShareExtAbility &extension)
53 {
54     extension.BatchInsert(FuzzUri(), FuzzVectorDataShareValuesBucket());
55 }
56 
Init()57 static inline MediaDataShareExtAbility Init()
58 {
59     const std::unique_ptr<AbilityRuntime::Runtime> runtime;
60     return {(*runtime)};
61 }
62 } // namespace OHOS
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
66 {
67     /* Run your code on data */
68     FuzzedDataProvider fdp(data, size);
69     OHOS::provider = &fdp;
70     if (data == nullptr) {
71         return 0;
72     }
73     auto extension = OHOS::Init();
74     OHOS::BatchInsertFuzzer(extension);
75     return 0;
76 }