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 "ziparchivehandle_fuzzer.h"
17
18 #include <string>
19 #include "libziparchive/zip_archive.h"
20
21 namespace OHOS {
ZipArchiveHandleFuzzTest(const uint8_t* data, size_t size)22 void ZipArchiveHandleFuzzTest(const uint8_t* data, size_t size)
23 {
24 std::string str(data, data + size);
25 {
26 // CloseArchive test
27 panda::ZipArchiveHandle handle = nullptr;
28 panda::CloseArchive(handle);
29 }
30 {
31 // CloseArchiveFile test
32 panda::ZipArchiveHandle handle = nullptr;
33 panda::CloseArchiveFile(handle);
34 }
35 {
36 // CloseCurrentFile test
37 panda::ZipArchiveHandle handle = nullptr;
38 panda::CloseCurrentFile(handle);
39 }
40 {
41 // ExtractToMemory test
42 panda::ZipArchiveHandle handle = nullptr;
43 uint8_t* buf = const_cast<uint8_t*>(data);
44 panda::ExtractToMemory(handle, buf, size);
45 }
46 {
47 // LocateFile test
48 panda::ZipArchiveHandle zipfile = nullptr;
49 const char* filename = str.c_str();
50 panda::LocateFile(zipfile, filename);
51 }
52 {
53 // OpenArchive test
54 panda::ZipArchiveHandle handle = nullptr;
55 const char* path = str.c_str();
56 panda::OpenArchive(handle, path);
57 }
58 {
59 // OpenArchiveFile test
60 panda::ZipArchiveHandle handle = nullptr;
61 FILE* fp = nullptr;
62 panda::OpenArchiveFile(handle, fp);
63 }
64 {
65 // OpenCurrentFile test
66 panda::ZipArchiveHandle handle = nullptr;
67 panda::OpenCurrentFile(handle);
68 }
69 }
70 }
71
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75 /* Run your code on data */
76 OHOS::ZipArchiveHandleFuzzTest(data, size);
77 return 0;
78 }