已合并
fix fuzztest errro and add new fuzztest #1833
AtomGit-Bot创建于 2022年7月19日
fix fuzztest errro and add new fuzztest #1833
已合并
AtomGit-Bot创建于 2022年7月19日
master合入到master
35 个文件变更+1020-44
MBUILD.gn+1-5
@@ -78,6 +78,7 @@ if (defined(ark_standalone_build)) {
78 "//arkcompiler/ets_runtime/ecmascript/tooling/test:unittest",78 "//arkcompiler/ets_runtime/ecmascript/tooling/test:unittest",
79 "//arkcompiler/ets_runtime/ecmascript/ts_types/tests:unittest",79 "//arkcompiler/ets_runtime/ecmascript/ts_types/tests:unittest",
80 ]80 ]
81+ deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ]
81 }82 }
82 }83 }
83 84 
@@ -116,11 +117,6 @@ if (defined(ark_standalone_build)) {
116 deps +=117 deps +=
117 [ "//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test" ]118 [ "//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test" ]
118 }119 }
119- 
120- # fuzz test
121- if (is_standard_system) {
122- deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ]
123- }
124 }120 }
125 }121 }
126}122}
Mtest/fuzztest/BUILD.gn+6-0
@@ -16,8 +16,14 @@ group("fuzztest") {
16 deps = []16 deps = []
17 17 
18 deps += [18 deps += [
19+ "biginttoint64_fuzzer:fuzztest",
20+ "biginttouint64_fuzzer:fuzztest",
21+ "createbigwords_fuzzer:fuzztest",
19 "dispatchprotocolmessage_fuzzer:fuzztest",22 "dispatchprotocolmessage_fuzzer:fuzztest",
20 "execute_fuzzer:fuzztest",23 "execute_fuzzer:fuzztest",
24+ "getwordsarray_fuzzer:fuzztest",
21 "initializedebugger_fuzzer:fuzztest",25 "initializedebugger_fuzzer:fuzztest",
26+ "newbigintbyint64_fuzzer:fuzztest",
27+ "newbigintbyuint64_fuzzer:fuzztest",
22 ]28 ]
23}29}
Atest/fuzztest/biginttoint64_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("BigIntToInt64FuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/biginttoint64_fuzzer"
27+ 
28+ sources = [ "biginttoint64_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":BigIntToInt64FuzzTest" ]
43+}
Atest/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.cpp+55-0
@@ -0,0 +1,55 @@
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 "biginttoint64_fuzzer.h"
17+#include "ecmascript/napi/include/jsnapi.h"
18+#include "ecmascript/log_wrapper.h"
19+#include "ecmascript/base/string_helper.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ void BigIntToInt64FuzzTest(const uint8_t* data, size_t size)
26+ {
27+ RuntimeOption option;
28+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
29+ EcmaVM *vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
31+ int64_t input = 0;
32+ size_t maxByteLen = 8;
33+ if (size > maxByteLen) {
34+ size = maxByteLen;
35+ }
36+ if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
37+ std::cout << "memcpy_s failed!";
38+ UNREACHABLE();
39+ }
40+ Local<BigIntRef> bigint = BigIntRef::New(vm, input);
41+ 
42+ int64_t cValue = 0;
43+ bool lossless = false;
44+ bigint->BigIntToInt64(vm, &cValue, &lossless);
45+ JSNApi::DestroyJSVM(vm);
46+ }
47+}
48+ 
49+// Fuzzer entry point.
50+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
51+{
52+ // Run your code on data.
53+ OHOS::BigIntToInt64FuzzTest(data, size);
54+ return 0;
55+}
Atest/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef BIGINTTOINT64_FUZZER_H
17+#define BIGINTTOINT64_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "biginttoint64_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/biginttoint64_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/biginttoint64_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>
Atest/fuzztest/biginttouint64_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("BigIntToUint64FuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/biginttouint64_fuzzer"
27+ 
28+ sources = [ "biginttouint64_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":BigIntToUint64FuzzTest" ]
43+}
Atest/fuzztest/biginttouint64_fuzzer/biginttouint64_fuzzer.cpp+55-0
@@ -0,0 +1,55 @@
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 "biginttouint64_fuzzer.h"
17+#include "ecmascript/napi/include/jsnapi.h"
18+#include "ecmascript/log_wrapper.h"
19+#include "ecmascript/base/string_helper.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ void BigIntToUint64FuzzTest(const uint8_t* data, size_t size)
26+ {
27+ RuntimeOption option;
28+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
29+ EcmaVM *vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
31+ uint64_t input = 0;
32+ size_t maxByteLen = 8;
33+ if (size > maxByteLen) {
34+ size = maxByteLen;
35+ }
36+ if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
37+ std::cout << "memcpy_s failed!";
38+ UNREACHABLE();
39+ }
40+ Local<BigIntRef> bigint = BigIntRef::New(vm, input);
41+ 
42+ uint64_t cValue = 0;
43+ bool lossless = false;
44+ bigint->BigIntToUint64(vm, &cValue, &lossless);
45+ JSNApi::DestroyJSVM(vm);
46+ }
47+}
48+ 
49+// Fuzzer entry point.
50+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
51+{
52+ // Run your code on data.
53+ OHOS::BigIntToUint64FuzzTest(data, size);
54+ return 0;
55+}
Atest/fuzztest/biginttouint64_fuzzer/biginttouint64_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef BIGINTTOUINT64_FUZZER_H
17+#define BIGINTTOUINT64_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "biginttouint64_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/biginttouint64_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/biginttouint64_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>
Atest/fuzztest/createbigwords_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("CreateBigWordsFuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/createbigwords_fuzzer"
27+ 
28+ sources = [ "createbigwords_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":CreateBigWordsFuzzTest" ]
43+}
Atest/fuzztest/createbigwords_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/createbigwords_fuzzer/createbigwords_fuzzer.cpp+83-0
@@ -0,0 +1,83 @@
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 "createbigwords_fuzzer.h"
17+#include "ecmascript/napi/include/jsnapi.h"
18+#include "ecmascript/log_wrapper.h"
19+#include "ecmascript/base/string_helper.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ void CreateBigWordsFuzzTest(const uint8_t* data, size_t size)
26+ {
27+ if (!size) {
28+ return;
29+ }
30+ 
31+ RuntimeOption option;
32+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
33+ EcmaVM *vm = JSNApi::CreateJSVM(option);
34+ [[maybe_unused]] LocalScope scope(vm);
35+ bool sign = true;
36+ const size_t uint64BytesNum = 8;
37+ if (size < uint64BytesNum) {
38+ uint64_t words = 0;
39+ if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) {
40+ std::cout << "memcpy_s failed!";
41+ UNREACHABLE();
42+ }
43+ BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word
44+ JSNApi::DestroyJSVM(vm);
45+ return;
46+ }
47+ 
48+ size_t wordsNum = size / uint64BytesNum;
49+ size_t hasRemain = size % uint64BytesNum;
50+ if (hasRemain) {
51+ wordsNum++;
52+ }
53+ std::vector<uint64_t> wordsVec;
54+ size_t count = uint64BytesNum;
55+ for (uint32_t i = 0; i < wordsNum; i++) {
56+ uint64_t word = 0;
57+ if (hasRemain && (i == (wordsNum - 1U))) {
58+ count = hasRemain;
59+ }
60+ if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) {
61+ std::cout << "memcpy_s failed!";
62+ UNREACHABLE();
63+ }
64+ wordsVec.push_back(word);
65+ data += count;
66+ }
67+ uint64_t *words = new uint64_t[wordsNum]();
68+ std::copy(wordsVec.begin(), wordsVec.end(), words);
69+ BigIntRef::CreateBigWords(vm, sign, wordsNum, words);
70+ delete[] words;
71+ words = nullptr;
72+ JSNApi::DestroyJSVM(vm);
73+ return;
74+ }
75+}
76+ 
77+// Fuzzer entry point.
78+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
79+{
80+ // Run your code on data.
81+ OHOS::CreateBigWordsFuzzTest(data, size);
82+ return 0;
83+}
Atest/fuzztest/createbigwords_fuzzer/createbigwords_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef CREATEBIGWORDS_FUZZER_H
17+#define CREATEBIGWORDS_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "createbigwords_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/createbigwords_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>
Mtest/fuzztest/dispatchprotocolmessage_fuzzer/dispatchprotocolmessage_fuzzer.cpp+5-11
@@ -14,8 +14,6 @@
14 */14 */
15 15 
16#include "dispatchprotocolmessage_fuzzer.h"16#include "dispatchprotocolmessage_fuzzer.h"
17-#include<cstddef>
18-#include<cstdint>
19#include "ecmascript/napi/include/jsnapi.h"17#include "ecmascript/napi/include/jsnapi.h"
20#include "ecmascript/tooling/debugger_service.h"18#include "ecmascript/tooling/debugger_service.h"
21 19 
@@ -23,20 +21,16 @@ using namespace panda;
23using namespace panda::ecmascript;21using namespace panda::ecmascript;
24using namespace panda::ecmascript::tooling;22using namespace panda::ecmascript::tooling;
25 23 
26-bool createstatus = true;
27namespace OHOS {24namespace OHOS {
28- bool DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size)25+ void DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size)
29 {26 {
30 RuntimeOption option;27 RuntimeOption option;
31- if (createstatus) {
32- JSNApi::CreateJSVM(option);
33- createstatus = false;
34- }
35 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);28 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
36- auto jsvm = JSNApi::CreateJSVM(option);29+ auto vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
37 std::string message(data, data+size);31 std::string message(data, data+size);
38- panda::ecmascript::tooling::DispatchMessage(jsvm, std::move(message));32+ DispatchMessage(vm, std::move(message));
39- return true;33+ JSNApi::DestroyJSVM(vm);
40 }34 }
41}35}
42 36 
Mtest/fuzztest/execute_fuzzer/execute_fuzzer.cpp+6-13
@@ -15,31 +15,24 @@
15 15 
16#include "execute_fuzzer.h"16#include "execute_fuzzer.h"
17#include "ecmascript/napi/include/jsnapi.h"17#include "ecmascript/napi/include/jsnapi.h"
18-#include "unistd.h"
19 18 
20using namespace panda;19using namespace panda;
21using namespace panda::ecmascript;20using namespace panda::ecmascript;
22-bool createstatus = true;
23namespace OHOS {21namespace OHOS {
24 // staic constexpr auto PANDA_MAIN_PATH = "pandastdlib/pandastdlib.bin";22 // staic constexpr auto PANDA_MAIN_PATH = "pandastdlib/pandastdlib.bin";
25 static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0";23 static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0";
26 24 
27- bool ExecuteFuzzTest(const uint8_t* data, size_t size)25+ void ExecuteFuzzTest(const uint8_t* data, size_t size)
28 {26 {
29 RuntimeOption option;27 RuntimeOption option;
30- if (createstatus) {
31- JSNApi::CreateJSVM(option);
32- createstatus = false;
33- }
34- 
35 option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);28 option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
36 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);29 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
37- auto jsvm = JSNApi::CreateJSVM(option);30+ auto vm = JSNApi::CreateJSVM(option);
38- Local<StringRef> entry = StringRef::NewFromUtf8(jsvm, PANDA_MAIN_FUNCTION);31+ [[maybe_unused]] LocalScope scope(vm);
32+ Local<StringRef> entry = StringRef::NewFromUtf8(vm, PANDA_MAIN_FUNCTION);
39 std::string a = entry->StringRef::ToString();33 std::string a = entry->StringRef::ToString();
40- JSNApi::Execute(jsvm, data, size, a);34+ JSNApi::Execute(vm, data, size, a);
41- JSNApi::DestroyJSVM(jsvm);35+ JSNApi::DestroyJSVM(vm);
42- return true;
43 }36 }
44}37}
45 38 
Atest/fuzztest/getwordsarray_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("GetWordsArrayFuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/getwordsarray_fuzzer"
27+ 
28+ sources = [ "getwordsarray_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":GetWordsArrayFuzzTest" ]
43+}
Atest/fuzztest/getwordsarray_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.cpp+83-0
@@ -0,0 +1,83 @@
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 "ecmascript/napi/include/jsnapi.h"
17+#include "ecmascript/log_wrapper.h"
18+#include "ecmascript/base/string_helper.h"
19+#include "getwordsarray_fuzzer.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ bool GetWordsArrayFuzzTest(const uint8_t* data, size_t size)
26+ {
27+ RuntimeOption option;
28+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
29+ EcmaVM *vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
31+ bool sign = true;
32+ const size_t uint64BytesNum = 8;
33+ if (size < uint64BytesNum) {
34+ uint64_t words = 0;
35+ if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) {
36+ std::cout << "memcpy_s failed!";
37+ UNREACHABLE();
38+ }
39+ Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word
40+ uint64_t *wordsArray = new uint64_t[1]();
41+ Local<BigIntRef> bigWords(bigWordsValue);
42+ bigWords->GetWordsArray(&sign, 1U, wordsArray);
43+ JSNApi::DestroyJSVM(vm);
44+ return true;
45+ }
46+ 
47+ size_t wordsNum = size / uint64BytesNum;
48+ size_t hasRemain = size % uint64BytesNum;
49+ if (hasRemain) {
50+ wordsNum++;
51+ }
52+ std::vector<uint64_t> wordsVec;
53+ size_t count = uint64BytesNum;
54+ for (uint32_t i = 0; i < wordsNum; i++) {
55+ uint64_t word = 0;
56+ if (hasRemain && (i == (wordsNum - 1U))) {
57+ count = hasRemain;
58+ }
59+ if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) {
60+ std::cout << "memcpy_s failed!";
61+ UNREACHABLE();
62+ }
63+ wordsVec.push_back(word);
64+ data += count;
65+ }
66+ uint64_t *words = new uint64_t[wordsNum]();
67+ std::copy(wordsVec.begin(), wordsVec.end(), words);
68+ Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, wordsNum, words);
69+ uint64_t *wordsArray = new uint64_t[wordsNum]();
70+ Local<BigIntRef> bigWords(bigWordsValue);
71+ bigWords->GetWordsArray(&sign, wordsNum, wordsArray);
72+ JSNApi::DestroyJSVM(vm);
73+ return true;
74+ }
75+}
76+ 
77+// Fuzzer entry point.
78+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
79+{
80+ // Run your code on data.
81+ OHOS::GetWordsArrayFuzzTest(data, size);
82+ return 0;
83+}
Atest/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef GETWORDSARRAY_FUZZER_H
17+#define GETWORDSARRAY_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "getwordsarray_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/getwordsarray_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>
Mtest/fuzztest/initializedebugger_fuzzer/initializedebugger_fuzzer.cpp+6-15
@@ -14,36 +14,27 @@
14 */14 */
15 15 
16#include "initializedebugger_fuzzer.h"16#include "initializedebugger_fuzzer.h"
17-#include <cstddef>
18-#include <cstdint>
19#include "ecmascript/napi/include/jsnapi.h"17#include "ecmascript/napi/include/jsnapi.h"
20#include "ecmascript/tooling/debugger_service.h"18#include "ecmascript/tooling/debugger_service.h"
21-#include "ecmascript/tooling/protocol_handler.h"
22-#include "unistd.h"
23 19 
24using namespace panda;20using namespace panda;
25using namespace panda::ecmascript;21using namespace panda::ecmascript;
26using namespace panda::ecmascript::tooling;22using namespace panda::ecmascript::tooling;
27 23 
28-bool createstatus = true;
29namespace OHOS {24namespace OHOS {
30- bool InitializeDebuggerFuzzTest(const uint8_t* data, size_t size)25+ void InitializeDebuggerFuzzTest(const uint8_t* data, size_t size)
31 {26 {
32 RuntimeOption option;27 RuntimeOption option;
33- if (createstatus) {
34- JSNApi::CreateJSVM(option);
35- createstatus = false;
36- }
37 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);28 option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
38- auto jsvm = JSNApi::CreateJSVM(option);29+ auto vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
39 using OnResponseType = const std::function<void(const void *, const std::string &)>;31 using OnResponseType = const std::function<void(const void *, const std::string &)>;
40 OnResponseType onResponse = [data, size](const void *d, [[maybe_unused]] const std::string &s) -> void {32 OnResponseType onResponse = [data, size](const void *d, [[maybe_unused]] const std::string &s) -> void {
41 d = data + size;33 d = data + size;
42 };34 };
43- panda::ecmascript::tooling::InitializeDebugger(jsvm, onResponse);35+ InitializeDebugger(vm, onResponse);
44- panda::ecmascript::tooling::UninitializeDebugger(jsvm);36+ UninitializeDebugger(vm);
45- JSNApi::DestroyJSVM(jsvm);37+ JSNApi::DestroyJSVM(vm);
46- return true;
47 }38 }
48}39}
49 40 
Atest/fuzztest/newbigintbyint64_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("NewBigIntByInt64FuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/newbigintbyint64_fuzzer"
27+ 
28+ sources = [ "newbigintbyint64_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":NewBigIntByInt64FuzzTest" ]
43+}
Atest/fuzztest/newbigintbyint64_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/newbigintbyint64_fuzzer/newbigintbyint64_fuzzer.cpp+51-0
@@ -0,0 +1,51 @@
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 "ecmascript/napi/include/jsnapi.h"
17+#include "ecmascript/log_wrapper.h"
18+#include "ecmascript/base/string_helper.h"
19+#include "newbigintbyint64_fuzzer.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ void NewBigIntByInt64FuzzTest(const uint8_t* data, size_t size)
26+ {
27+ RuntimeOption option;
28+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
29+ EcmaVM *vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
31+ int64_t input = 0;
32+ size_t maxByteLen = 8;
33+ if (size > maxByteLen) {
34+ size = maxByteLen;
35+ }
36+ if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
37+ std::cout << "memcpy_s failed!";
38+ UNREACHABLE();
39+ }
40+ BigIntRef::New(vm, input);
41+ JSNApi::DestroyJSVM(vm);
42+ }
43+}
44+ 
45+// Fuzzer entry point.
46+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47+{
48+ // Run your code on data.
49+ OHOS::NewBigIntByInt64FuzzTest(data, size);
50+ return 0;
51+}
Atest/fuzztest/newbigintbyint64_fuzzer/newbigintbyint64_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef NEWBIGINTBYINT64_FUZZER_H
17+#define NEWBIGINTBYINT64_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "newbigintbyint64_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/newbigintbyint64_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>
Atest/fuzztest/newbigintbyuint64_fuzzer/BUILD.gn+43-0
@@ -0,0 +1,43 @@
1+# Copyright (c) 2022 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#####################################hydra-fuzz###############################
15+import("//arkcompiler/ets_runtime/js_runtime_config.gni")
16+import("//arkcompiler/ets_runtime/test/test_helper.gni")
17+import("//build/config/features.gni")
18+import("//build/ohos.gni")
19+import("//build/test.gni")
20+ 
21+####################################fuzztest##################################
22+ohos_fuzztest("NewBigIntByUint64FuzzTest") {
23+ module_out_path = "arkcompiler/ets_runtime"
24+ 
25+ fuzz_config_file =
26+ "//arkcompiler/ets_runtime/test/fuzztest/newbigintbyuint64_fuzzer"
27+ 
28+ sources = [ "newbigintbyuint64_fuzzer.cpp" ]
29+ 
30+ configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
31+ 
32+ deps = [
33+ "$ark_root/libpandabase:libarkbase",
34+ "//arkcompiler/ets_runtime:libark_jsruntime",
35+ sdk_libc_secshared_dep,
36+ ]
37+}
38+ 
39+group("fuzztest") {
40+ testonly = true
41+ deps = []
42+ deps += [ ":NewBigIntByUint64FuzzTest" ]
43+}
Atest/fuzztest/newbigintbyuint64_fuzzer/corpus/init+14-0
@@ -0,0 +1,14 @@
1+# Copyright (c) 2021 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+FUZZ
Atest/fuzztest/newbigintbyuint64_fuzzer/newbigintbyuint64_fuzzer.cpp+51-0
@@ -0,0 +1,51 @@
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 "ecmascript/napi/include/jsnapi.h"
17+#include "ecmascript/log_wrapper.h"
18+#include "ecmascript/base/string_helper.h"
19+#include "newbigintbyuint64_fuzzer.h"
20+ 
21+using namespace panda;
22+using namespace panda::ecmascript;
23+ 
24+namespace OHOS {
25+ void NewBigIntByUint64FuzzTest(const uint8_t* data, size_t size)
26+ {
27+ RuntimeOption option;
28+ option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
29+ EcmaVM *vm = JSNApi::CreateJSVM(option);
30+ [[maybe_unused]] LocalScope scope(vm);
31+ uint64_t input = 0;
32+ size_t maxByteLen = 8;
33+ if (size > maxByteLen) {
34+ size = maxByteLen;
35+ }
36+ if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
37+ std::cout << "memcpy_s failed!";
38+ UNREACHABLE();
39+ }
40+ BigIntRef::New(vm, input);
41+ JSNApi::DestroyJSVM(vm);
42+ }
43+}
44+ 
45+// Fuzzer entry point.
46+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47+{
48+ // Run your code on data.
49+ OHOS::NewBigIntByUint64FuzzTest(data, size);
50+ return 0;
51+}
Atest/fuzztest/newbigintbyuint64_fuzzer/newbigintbyuint64_fuzzer.h+21-0
@@ -0,0 +1,21 @@
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+#ifndef NEWBIGINTBYUINT64_FUZZER_H
17+#define NEWBIGINTBYUINT64_FUZZER_H
18+ 
19+#define FUZZ_PROJECT_NAME "newbigintbyuint64_fuzzer.h"
20+ 
21+#endif
Atest/fuzztest/newbigintbyuint64_fuzzer/project.xml+25-0
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
3+ 
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+ 
8+ http://www.apache.org/licenses/LICENSE-2.0
9+ 
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+<fuzz_config>
17+ <fuzztest>
18+ <!-- maximum length of a test input -->
19+ <max_len>1000</max_len>
20+ <!-- maximum total time in seconds to run the fuzzer -->
21+ <max_total_time>300</max_total_time>
22+ <!-- memory usage limit in Mb -->
23+ <rss_limit_mb>4096</rss_limit_mb>
24+ </fuzztest>
25+</fuzz_config>