mirror of
https://github.com/openharmony/ark_runtime_core.git
synced 2026-07-01 13:17:23 -04:00
Add fuzztest
Signed-off-by: wangyantian <wangyantian@huawei.com> Change-Id: I51b6e6e2bc08eb42a1fee73ab8586fc19823a873
This commit is contained in:
+3
-1
@@ -29,7 +29,9 @@
|
||||
"//ark/runtime_core:ark_packages"
|
||||
],
|
||||
"inner_kits": [],
|
||||
"test": []
|
||||
"test": [
|
||||
"//ark/runtime_core/tests/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -253,6 +253,13 @@ std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location,
|
||||
LOG(ERROR, PANDAFILE) << "GetCurrentFileInfo error";
|
||||
return nullptr;
|
||||
}
|
||||
// check that file is not empty, otherwise crash at CloseArchiveFile
|
||||
if (entry.GetUncompressedSize() == 0) {
|
||||
OpenPandaFileFromZipErrorHandler(zipfile);
|
||||
LOG(ERROR, PANDAFILE) << "Invalid panda file '" << (try_default ? ARCHIVE_FILENAME : archive_filename)
|
||||
<< "'";
|
||||
return nullptr;
|
||||
}
|
||||
if (OpenCurrentFile(zipfile) != ZIPARCHIVE_OK) {
|
||||
CloseCurrentFile(zipfile);
|
||||
OpenPandaFileFromZipErrorHandler(zipfile);
|
||||
@@ -531,7 +538,11 @@ std::unique_ptr<const File> File::OpenUncompressedArchive(int fd, const std::str
|
||||
|
||||
bool CheckHeader(const os::mem::ConstBytePtr &ptr, const std::string_view &filename)
|
||||
{
|
||||
auto header = reinterpret_cast<const File::Header *>(ptr.Get());
|
||||
if (ptr.Get() == nullptr || ptr.GetSize() < sizeof(File::Header)) {
|
||||
LOG(ERROR, PANDAFILE) << "Invalid panda file '" << filename << "'";
|
||||
return false;
|
||||
}
|
||||
auto header = reinterpret_cast<const File::Header *>(reinterpret_cast<uintptr_t>(ptr.Get()));
|
||||
if (header->magic != File::MAGIC) {
|
||||
LOG(ERROR, PANDAFILE) << "Invalid panda file '" << filename << "'";
|
||||
return false;
|
||||
@@ -543,7 +554,7 @@ bool CheckHeader(const os::mem::ConstBytePtr &ptr, const std::string_view &filen
|
||||
/* static */
|
||||
std::unique_ptr<const File> File::OpenFromMemory(os::mem::ConstBytePtr &&ptr)
|
||||
{
|
||||
auto header = reinterpret_cast<const Header *>(ptr.Get());
|
||||
auto header = reinterpret_cast<const Header *>(reinterpret_cast<uintptr_t>(ptr.Get()));
|
||||
if (header->magic != File::MAGIC) {
|
||||
LOG(ERROR, PANDAFILE) << "Invalid panda file";
|
||||
return nullptr;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
"checkheader_fuzzer:fuzztest",
|
||||
"literaldataaccessor_fuzzer:fuzztest",
|
||||
"methoddataaccessor_fuzzer:fuzztest",
|
||||
"open_fuzzer:fuzztest",
|
||||
"openfrommemory1arg_fuzzer:fuzztest",
|
||||
"openfrommemory2arg_fuzzer:fuzztest",
|
||||
"openpandafile_fuzzer:fuzztest",
|
||||
"openpandafilefrommemory_fuzzer:fuzztest",
|
||||
"openpandafileorzip_fuzzer:fuzztest",
|
||||
"openuncompressedarchive_fuzzer:fuzztest",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("CheckHeaderFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//ark/runtime_core/tests/fuzztest/checkheader_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "checkheader_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":CheckHeaderFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "checkheader_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
namespace OHOS {
|
||||
void CheckHeaderFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
// Write data into a temp file
|
||||
const char *filename = "__ChechHeaderFuzzTest_data.tmp";
|
||||
FILE *fp = fopen(filename, "w+");
|
||||
if (fp == nullptr) {
|
||||
return;
|
||||
}
|
||||
(void)fwrite(data, sizeof(uint8_t), size, fp);
|
||||
(void)fseek(fp, 0, SEEK_SET);
|
||||
|
||||
auto file = panda::os::file::File(fileno(fp));
|
||||
panda::os::mem::ConstBytePtr ptr =
|
||||
panda::os::mem::MapFile(file, panda::os::mem::MMAP_PROT_READ, panda::os::mem::MMAP_FLAG_PRIVATE, size, 0)
|
||||
.ToConst();
|
||||
panda::panda_file::CheckHeader(ptr, filename);
|
||||
(void)fclose(fp);
|
||||
(void)remove(filename);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::CheckHeaderFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CHECKHEADER_FUZZER_H
|
||||
#define CHECKHEADER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "checkheader_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("LiteralDataAccessorFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/literaldataaccessor_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "literaldataaccessor_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":LiteralDataAccessorFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "literaldataaccessor_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
#include "libpandafile/literal_data_accessor.h"
|
||||
|
||||
namespace OHOS {
|
||||
void LiteralDataAccessorFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size);
|
||||
if (pf == nullptr) {
|
||||
return;
|
||||
}
|
||||
panda::panda_file::File::EntityId literal_arrays_id = pf->GetLiteralArraysId();
|
||||
panda::panda_file::LiteralDataAccessor(*pf, literal_arrays_id);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::LiteralDataAccessorFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LITERALDATAACCESSOR_FUZZER_H
|
||||
#define LITERALDATAACCESSOR_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "literaldataaccessor_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("MethodDataAccessorFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/methoddataaccessor_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "methoddataaccessor_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":MethodDataAccessorFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "methoddataaccessor_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
#include "libpandafile/method_data_accessor.h"
|
||||
#include "libpandafile/class_data_accessor-inl.h"
|
||||
|
||||
namespace OHOS {
|
||||
void MethodDataAccessorFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size);
|
||||
if (pf == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto classes = pf->GetClasses();
|
||||
const auto &panda_file = *pf;
|
||||
for (size_t i = 0; i < classes.Size(); i++) {
|
||||
panda::panda_file::File::EntityId id(classes[i]);
|
||||
if (panda_file.IsExternal(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
panda::panda_file::ClassDataAccessor cda(panda_file, id);
|
||||
cda.EnumerateMethods([&](const panda::panda_file::MethodDataAccessor &mda) {});
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::MethodDataAccessorFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef METHODDATAACCESSOR_FUZZER_H
|
||||
#define METHODDATAACCESSOR_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "methoddataaccessor_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//ark/runtime_core/tests/fuzztest/open_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "open_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "open_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
const char *filename = "__OpenFuzzTest_data.tmp";
|
||||
FILE *fp = fopen(filename, "w");
|
||||
if (fp == nullptr) {
|
||||
return;
|
||||
}
|
||||
(void)fwrite(data, sizeof(uint8_t), size, fp);
|
||||
(void)fclose(fp);
|
||||
|
||||
{
|
||||
panda::panda_file::File::Open(filename);
|
||||
}
|
||||
// Remove the temp file
|
||||
(void)remove(filename);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPEN_FUZZER_H
|
||||
#define OPEN_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "open_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenFromMemory1ArgFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/openfrommemory1arg_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openfrommemory1arg_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenFromMemory1ArgFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openfrommemory1arg_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenFromMemory1ArgFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
panda::os::mem::ConstBytePtr ptr(
|
||||
reinterpret_cast<std::byte *>(reinterpret_cast<uintptr_t>(const_cast<uint8_t *>(data))), size,
|
||||
[](std::byte *, size_t) noexcept {});
|
||||
panda::panda_file::File::OpenFromMemory(std::move(ptr));
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenFromMemory1ArgFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENFROMMEMORY1_FUZZER_H
|
||||
#define OPENFROMMEMORY1_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openfrommemory1arg_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenFromMemory2ArgFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/openfrommemory2arg_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openfrommemory2arg_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenFromMemory2ArgFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openfrommemory2arg_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenFromMemory2ArgFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
panda::os::mem::ConstBytePtr ptr(
|
||||
reinterpret_cast<std::byte *>(reinterpret_cast<uintptr_t>(const_cast<uint8_t *>(data))), size,
|
||||
[](std::byte *, size_t) noexcept {});
|
||||
std::hash<const uint8_t *> hash;
|
||||
panda::panda_file::File::OpenFromMemory(std::move(ptr), std::to_string(hash(data)));
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenFromMemory2ArgFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENFROMMEMORY2_FUZZER_H
|
||||
#define OPENFROMMEMORY2_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openfrommemory2arg_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenPandaFileFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//ark/runtime_core/tests/fuzztest/openpandafile_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openpandafile_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenPandaFileFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openpandafile_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
#include "libziparchive/zip_archive.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenPandaFileFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
// Create zip file
|
||||
const char *filename1 = panda::panda_file::ARCHIVE_FILENAME;
|
||||
const char *filename2 = "classes1.abc";
|
||||
|
||||
const char *zip_filename1 = "__OpenPandaFileFuzzTest.zip";
|
||||
int ret1 =
|
||||
panda::CreateOrAddFileIntoZip(zip_filename1, filename1, data, size, APPEND_STATUS_CREATE, Z_BEST_COMPRESSION);
|
||||
int ret2 =
|
||||
panda::CreateOrAddFileIntoZip(zip_filename1, filename2, data, size, APPEND_STATUS_ADDINZIP, Z_BEST_COMPRESSION);
|
||||
if (ret1 != 0 || ret2 != 0) {
|
||||
(void)remove(zip_filename1);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *zip_filename2 = "__OpenPandaFileFromZipNameAnonMem.zip";
|
||||
int ret3 =
|
||||
panda::CreateOrAddFileIntoZip(zip_filename2, filename1, data, size, APPEND_STATUS_CREATE, Z_BEST_COMPRESSION);
|
||||
if (ret3 != 0) {
|
||||
(void)remove(zip_filename2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Call OpenPandaFile
|
||||
{
|
||||
panda::panda_file::OpenPandaFile(zip_filename1);
|
||||
panda::panda_file::OpenPandaFile(zip_filename2);
|
||||
}
|
||||
(void)remove(zip_filename1);
|
||||
(void)remove(zip_filename2);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenPandaFileFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENPANDAFILE_FUZZER_H
|
||||
#define OPENPANDAFILE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openpandafile_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenPandaFileFromMemoryFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/openpandafilefrommemory_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openpandafilefrommemory_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenPandaFileFromMemoryFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openpandafilefrommemory_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenPandaFileFromMemoryFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
panda::panda_file::OpenPandaFileFromMemory(data, size);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenPandaFileFromMemoryFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENPANDAFILEFROMMEMORY_FUZZER_H
|
||||
#define OPENPANDAFILEFROMMEMORY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openpandafilefrommemory_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenPandaFileOrZipFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/openpandafileorzip_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openpandafileorzip_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenPandaFileOrZipFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openpandafileorzip_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
#include "libziparchive/zip_archive.h"
|
||||
|
||||
namespace OHOS {
|
||||
void OpenPandaFileOrZipFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
const char *filename1 = panda::panda_file::ARCHIVE_FILENAME;
|
||||
const char *filename2 = "classes1.abc";
|
||||
// Create uncompressed zip file
|
||||
const char *uncompress_zip_filename = "__OpenPandaFileOrZipFuzzTest_uncompress.zip";
|
||||
int ret1 = panda::CreateOrAddFileIntoZip(uncompress_zip_filename, filename1, data, size, APPEND_STATUS_CREATE,
|
||||
Z_NO_COMPRESSION);
|
||||
int ret2 = panda::CreateOrAddFileIntoZip(uncompress_zip_filename, filename2, data, size, APPEND_STATUS_ADDINZIP,
|
||||
Z_NO_COMPRESSION);
|
||||
if (ret1 != 0 || ret2 != 0) {
|
||||
(void)remove(uncompress_zip_filename);
|
||||
return;
|
||||
}
|
||||
// Create compressed zip file
|
||||
const char *compressed_zip_filename = "__OpenPandaFileOrZipFuzzTest_compressed.zip";
|
||||
ret1 = panda::CreateOrAddFileIntoZip(uncompress_zip_filename, filename1, data, size, APPEND_STATUS_CREATE,
|
||||
Z_BEST_COMPRESSION);
|
||||
ret2 = panda::CreateOrAddFileIntoZip(uncompress_zip_filename, filename2, data, size, APPEND_STATUS_ADDINZIP,
|
||||
Z_BEST_COMPRESSION);
|
||||
if (ret1 != 0 || ret2 != 0) {
|
||||
(void)remove(compressed_zip_filename);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
panda::panda_file::OpenPandaFileOrZip(uncompress_zip_filename);
|
||||
panda::panda_file::OpenPandaFileOrZip(compressed_zip_filename);
|
||||
}
|
||||
(void)remove(uncompress_zip_filename);
|
||||
(void)remove(compressed_zip_filename);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenPandaFileOrZipFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENPANDAFILEORZIP_FUZZER_H
|
||||
#define OPENPANDAFILEORZIP_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openpandafileorzip_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/test.gni")
|
||||
module_output_path = "ark/runtime_core"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("OpenUncompressedArchiveFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"//ark/runtime_core/tests/fuzztest/openuncompressedarchive_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "openuncompressedarchive_fuzzer.cpp" ]
|
||||
deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":OpenUncompressedArchiveFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "openuncompressedarchive_fuzzer.h"
|
||||
#include "libpandafile/file.h"
|
||||
#include "libziparchive/zip_archive.h"
|
||||
|
||||
namespace OHOS {
|
||||
void CloseAndRemoveZipFile(panda::ZipArchiveHandle &handle, FILE *fp, const char *filename)
|
||||
{
|
||||
panda::CloseArchiveFile(handle);
|
||||
(void)fclose(fp);
|
||||
(void)remove(filename);
|
||||
}
|
||||
|
||||
void OpenUncompressedArchiveFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
// Create zip file
|
||||
const char *zip_filename = "__OpenUncompressedArchiveFuzzTest.zip";
|
||||
const char *filename = panda::panda_file::ARCHIVE_FILENAME;
|
||||
int ret = panda::CreateOrAddFileIntoZip(zip_filename, filename, data, size, APPEND_STATUS_CREATE, Z_NO_COMPRESSION);
|
||||
if (ret != 0) {
|
||||
(void)remove(zip_filename);
|
||||
return;
|
||||
}
|
||||
|
||||
// Acquire entry
|
||||
#ifdef PANDA_TARGET_WINDOWS
|
||||
constexpr char const *mode = "rb";
|
||||
#else
|
||||
constexpr char const *mode = "rbe";
|
||||
#endif
|
||||
FILE *fp = fopen(zip_filename, mode);
|
||||
if (fp == nullptr) {
|
||||
(void)remove(zip_filename);
|
||||
return;
|
||||
}
|
||||
panda::ZipArchiveHandle zipfile = nullptr;
|
||||
if (panda::OpenArchiveFile(zipfile, fp) != panda::ZIPARCHIVE_OK) {
|
||||
(void)fclose(fp);
|
||||
(void)remove(zip_filename);
|
||||
return;
|
||||
}
|
||||
if (panda::LocateFile(zipfile, filename) != panda::ZIPARCHIVE_OK) {
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
return;
|
||||
}
|
||||
panda::EntryFileStat entry;
|
||||
if (panda::GetCurrentFileInfo(zipfile, &entry) != panda::ZIPARCHIVE_OK) {
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
return;
|
||||
}
|
||||
if (panda::OpenCurrentFile(zipfile) != panda::ZIPARCHIVE_OK) {
|
||||
panda::CloseCurrentFile(zipfile);
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
return;
|
||||
}
|
||||
panda::GetCurrentFileOffset(zipfile, &entry);
|
||||
// Call OpenUncompressedArchive
|
||||
{
|
||||
panda::panda_file::File::OpenUncompressedArchive(fileno(fp), zip_filename, entry.GetUncompressedSize(),
|
||||
entry.GetOffset());
|
||||
}
|
||||
panda::CloseCurrentFile(zipfile);
|
||||
CloseAndRemoveZipFile(zipfile, fp, zip_filename);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::OpenUncompressedArchiveFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OPENUNCOMPRESSEDARCHIVE_FUZZER_H
|
||||
#define OPENUNCOMPRESSEDARCHIVE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "openuncompressedarchive_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
Reference in New Issue
Block a user