1 /*
2 * Copyright (c) 2022 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 "classdataaccessor_fuzzer.h"
17
18 #include "libpandafile/file.h"
19 #include "libpandafile/class_data_accessor-inl.h"
20
21 namespace OHOS {
ClassDataAccessorFuzzTest(const uint8_t * data,size_t size)22 void ClassDataAccessorFuzzTest(const uint8_t* data, size_t size)
23 {
24 try {
25 auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size);
26 if (pf == nullptr) {
27 return;
28 }
29 auto classes = pf->GetClasses();
30 const auto &panda_file = *pf;
31 for (size_t i = 0; i < classes.Size(); i++) {
32 panda::panda_file::File::EntityId id(classes[i]);
33 if (panda_file.IsExternal(id)) {
34 continue;
35 }
36
37 panda::panda_file::ClassDataAccessor cda(panda_file, id);
38 }
39 } catch (panda::panda_file::helpers::FileAccessException &e) {
40 // Known exception, no need exposing
41 }
42 }
43 } // namespace OHOS
44
45 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47 {
48 /* Run your code on data */
49 OHOS::ClassDataAccessorFuzzTest(data, size);
50 return 0;
51 }
52