• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "createoraddfileintozip_fuzzer.h"
17 #include "libpandafile/file.h"
18 #include "libziparchive/zip_archive.h"
19 
20 namespace OHOS {
CreateOrAddFileIntoZipFuzzTest(const uint8_t * data,size_t size)21     void CreateOrAddFileIntoZipFuzzTest(const uint8_t* data, size_t size)
22     {
23         std::string str(data, data + size);
24         {
25             // zipOpen test
26             const char* zipname = nullptr;
27             const char* filename = str.c_str();
28             panda::CreateOrAddFileIntoZip(zipname, filename, data, size, APPEND_STATUS_CREATE, Z_NO_COMPRESSION);
29             (void)remove(zipname);
30         }
31         {
32             // zipOpenNewFileInZip test
33             const char* zipname = str.c_str();
34             const char* filename = nullptr;
35             panda::CreateOrAddFileIntoZip(zipname, filename, data, size, APPEND_STATUS_CREATE, Z_NO_COMPRESSION);
36             (void)remove(zipname);
37         }
38         {
39             // zipWriteInFileInZip test
40             const char* zipname = str.c_str();
41             const char* filename = panda::panda_file::ARCHIVE_FILENAME;
42             panda::CreateOrAddFileIntoZip(zipname, filename, data, 0, APPEND_STATUS_CREATE, Z_NO_COMPRESSION);
43             (void)remove(zipname);
44         }
45     }
46 }
47 
48 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)49 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
50 {
51     /* Run your code on data */
52     OHOS::CreateOrAddFileIntoZipFuzzTest(data, size);
53     return 0;
54 }
55 
56