From 3efd90806211c6767585a95586bb7176e8ddb89d Mon Sep 17 00:00:00 2001 From: coollixin Date: Tue, 30 Jan 2024 15:21:34 +0800 Subject: [PATCH 01/10] hashset next modify issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8ZXBB Signed-off-by: coollixin --- ecmascript/js_api/js_api_hashset_iterator.cpp | 2 +- ecmascript/js_api/js_api_lightweightset_iterator.cpp | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ecmascript/js_api/js_api_hashset_iterator.cpp b/ecmascript/js_api/js_api_hashset_iterator.cpp index 3e5d261ef3..46f73d44a6 100644 --- a/ecmascript/js_api/js_api_hashset_iterator.cpp +++ b/ecmascript/js_api/js_api_hashset_iterator.cpp @@ -65,7 +65,7 @@ JSTaggedValue JSAPIHashSetIterator::Next(EcmaRuntimeCallInfo *argv) } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle array = factory->NewTaggedArray(2); // 2 means the length of array - array->Set(thread, 0, JSTaggedValue(--index)); + array->Set(thread, 0, valueHandle); array->Set(thread, 1, valueHandle); JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); diff --git a/ecmascript/js_api/js_api_lightweightset_iterator.cpp b/ecmascript/js_api/js_api_lightweightset_iterator.cpp index 133390f45b..0e589a3396 100644 --- a/ecmascript/js_api/js_api_lightweightset_iterator.cpp +++ b/ecmascript/js_api/js_api_lightweightset_iterator.cpp @@ -65,12 +65,9 @@ JSTaggedValue JSAPILightWeightSetIterator::Next(EcmaRuntimeCallInfo *argv) if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } - TaggedArray *hashArray = - TaggedArray::Cast(JSHandle(lightWeightSet)->GetHashes().GetTaggedObject()); - JSHandle keyHandle(thread, hashArray->Get(index)); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle array = factory->NewTaggedArray(2); // 2 means the length of array - array->Set(thread, 0, keyHandle); + array->Set(thread, 0, value); array->Set(thread, 1, value); JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); -- Gitee From f3be3bb8d0ea6f7112aa391dd720b96df42098c4 Mon Sep 17 00:00:00 2001 From: lanhaibo4 Date: Tue, 30 Jan 2024 20:39:04 +0800 Subject: [PATCH 02/10] Signed-off-by: lanhaibo4 issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I900V7 --- .../jsnapidestory_fuzzer.cpp | 2 + .../fuzztest/jsnapidestory_fuzzer/project.xml | 2 +- .../jsnapiexecute_fuzzer.cpp | 10 +- .../jsvalueref_fuzzer/jsvalueref_fuzzer.cpp | 14 +- .../jsvaluerefintegervalue_fuzzer.cpp | 6 +- .../jsvaluerefobject_fuzzer.cpp | 4 +- .../proxyrefisrevoked_fuzzer.cpp | 18 +- .../stringrefnewfromutf16_fuzzer.cpp | 2 +- .../stringrefwriteutf16_fuzzer.cpp | 17 +- test/resource/js_runtime/ohos_test.xml | 225 ++++++++++++++++++ 10 files changed, 263 insertions(+), 37 deletions(-) diff --git a/test/fuzztest/jsnapidestory_fuzzer/jsnapidestory_fuzzer.cpp b/test/fuzztest/jsnapidestory_fuzzer/jsnapidestory_fuzzer.cpp index e12f64e1c6..9d74eba9c9 100644 --- a/test/fuzztest/jsnapidestory_fuzzer/jsnapidestory_fuzzer.cpp +++ b/test/fuzztest/jsnapidestory_fuzzer/jsnapidestory_fuzzer.cpp @@ -44,6 +44,8 @@ void JSNApiDestroyPGOProfilerFuzzTest([[maybe_unused]]const uint8_t *data, size_ if (size <= 0) { return; } + JSRuntimeOptions runtimeOptions; + JSNApi::InitializePGOProfiler(runtimeOptions); JSNApi::DestroyPGOProfiler(); JSNApi::DestroyJSVM(vm); } diff --git a/test/fuzztest/jsnapidestory_fuzzer/project.xml b/test/fuzztest/jsnapidestory_fuzzer/project.xml index 4fdbc407f2..b34b12ca9c 100644 --- a/test/fuzztest/jsnapidestory_fuzzer/project.xml +++ b/test/fuzztest/jsnapidestory_fuzzer/project.xml @@ -20,6 +20,6 @@ 300 - 4096 + 5120 diff --git a/test/fuzztest/jsnapiexecute_fuzzer/jsnapiexecute_fuzzer.cpp b/test/fuzztest/jsnapiexecute_fuzzer/jsnapiexecute_fuzzer.cpp index 50405bde8c..0489fb4097 100644 --- a/test/fuzztest/jsnapiexecute_fuzzer/jsnapiexecute_fuzzer.cpp +++ b/test/fuzztest/jsnapiexecute_fuzzer/jsnapiexecute_fuzzer.cpp @@ -32,12 +32,16 @@ void JSNApiExecuteFuzztest(const uint8_t *data, size_t size) LOG_ECMA(ERROR) << "illegal input!"; return; } - char *value = new char[size](); - memset_s(value, size, 0, size); - if (memcpy_s(value, size, data, size) != EOK) { + char *value = new char[size + 1](); + if (memset_s(value, size + 1, 0, size + 1) != EOK) { + LOG_ECMA(ERROR) << "memset_s failed!"; + UNREACHABLE(); + } + if (memcpy_s(value, size + 1, data, size) != EOK) { LOG_ECMA(ERROR) << "memcpy_s failed!"; UNREACHABLE(); } + value[size] = '\0'; const std::string fileName = value; bool needUpdate = size % DIVISOR ? true : false; // 2:Cannot divide by 2 as true, otherwise it is false JSNApi::Execute(vm, fileName, fileName, needUpdate); diff --git a/test/fuzztest/jsvalueref_fuzzer/jsvalueref_fuzzer.cpp b/test/fuzztest/jsvalueref_fuzzer/jsvalueref_fuzzer.cpp index dfb4f153e2..e06d093dcf 100644 --- a/test/fuzztest/jsvalueref_fuzzer/jsvalueref_fuzzer.cpp +++ b/test/fuzztest/jsvalueref_fuzzer/jsvalueref_fuzzer.cpp @@ -30,11 +30,7 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - uint8_t* ptr = nullptr; - ptr = const_cast(data); - char16_t utf16[] = u"This is a char16 array"; - int size1 = sizeof(utf16); - Local obj = StringRef::NewFromUtf16(vm, utf16, size1); + Local obj = StringRef::NewFromUtf8(vm, "TestKey"); obj->IsNull(); JSNApi::DestroyJSVM(vm); } @@ -48,12 +44,8 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - uint8_t* ptr = nullptr; - ptr = const_cast(data); - char16_t utf16[] = u"This is a char16 array"; - int size1 = sizeof(utf16); - Local obj = StringRef::NewFromUtf16(vm, utf16, size1); - obj->IsBoolean(); + Local tag = BooleanRef::New(vm, false); + tag->IsBoolean(); JSNApi::DestroyJSVM(vm); } } diff --git a/test/fuzztest/jsvaluerefintegervalue_fuzzer/jsvaluerefintegervalue_fuzzer.cpp b/test/fuzztest/jsvaluerefintegervalue_fuzzer/jsvaluerefintegervalue_fuzzer.cpp index 68b4805957..d0d5a46806 100644 --- a/test/fuzztest/jsvaluerefintegervalue_fuzzer/jsvaluerefintegervalue_fuzzer.cpp +++ b/test/fuzztest/jsvaluerefintegervalue_fuzzer/jsvaluerefintegervalue_fuzzer.cpp @@ -26,11 +26,15 @@ using namespace panda::ecmascript; #endif namespace OHOS { -void JSValueRefIntegerValueFuzzTest([[maybe_unused]] const uint8_t *data, [[maybe_unused]] size_t size) +void JSValueRefIntegerValueFuzzTest(const uint8_t *data, size_t size) { RuntimeOption option; option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } Local globalObject = NumberRef::New(vm, 0xffffffffffff); int64_t i64 = globalObject->IntegerValue(vm); UNUSED(i64); diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp index 195b9505b5..ab7f878597 100644 --- a/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp +++ b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp @@ -92,7 +92,7 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - int length = 8; + int length = size / sizeof(char16_t); Local obj = StringRef::NewFromUtf16(vm, (char16_t*)data, length); obj->IsJSPrimitiveBoolean(); JSNApi::DestroyJSVM(vm); @@ -107,7 +107,7 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - int length = 8; + int length = size / sizeof(char16_t); Local obj = StringRef::NewFromUtf16(vm, (char16_t*)data, length); obj->IsGeneratorFunction(); JSNApi::DestroyJSVM(vm); diff --git a/test/fuzztest/proxyrefisrevoked_fuzzer/proxyrefisrevoked_fuzzer.cpp b/test/fuzztest/proxyrefisrevoked_fuzzer/proxyrefisrevoked_fuzzer.cpp index 9ff3fe57eb..38b2dabc18 100644 --- a/test/fuzztest/proxyrefisrevoked_fuzzer/proxyrefisrevoked_fuzzer.cpp +++ b/test/fuzztest/proxyrefisrevoked_fuzzer/proxyrefisrevoked_fuzzer.cpp @@ -31,22 +31,8 @@ void ProxyRefIsRevokedFuzzTest(const uint8_t *data, size_t size) LOG_ECMA(ERROR) << "illegal input!"; return; } - auto thread_ = vm->GetAssociatedJSThread(); - uint8_t *ptr = nullptr; - ptr = const_cast(data); - JSHandle env = vm->GetGlobalEnv(); - ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); - JSHandle hclass(thread_, env->GetObjectFunction().GetObject()); - JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); - JSHandle key(factory->NewFromASCII("x")); - JSHandle value(thread_, JSTaggedValue(size)); - JSObject::SetProperty(thread_, targetHandle, key, value); - JSHandle handlerHandle( - factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); - JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); - JSHandle proxyTagValue = JSHandle::Cast(proxyHandle); - Local object = JSNApiHelper::ToLocal(proxyTagValue); - object->IsRevoked(); + Local tag = ProxyRef::New(vm); + tag->IsRevoked(); JSNApi::DestroyJSVM(vm); } } diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp index 8ae5f8628e..efe780f77b 100644 --- a/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - StringRef::NewFromUtf16(vm, (char16_t*)data); + StringRef::NewFromUtf16(vm, (char16_t*)data, size / sizeof(char16_t)); JSNApi::DestroyJSVM(vm); return; } diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp index e9be6bca22..32db977543 100644 --- a/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp @@ -32,8 +32,21 @@ namespace OHOS { LOG_ECMA(ERROR) << "illegal input!"; return; } - Local res = StringRef::NewFromUtf16(vm, (char16_t*)data); - res->WriteUtf16((char16_t*)data, (int)size); + int length = size / sizeof(char16_t); + char16_t* buffer = new char16_t[length]; + if (memset_s(buffer, length, 0, length) != EOK) { + LOG_ECMA(ERROR) << "memset_s fail!"; + UNREACHABLE(); + } + Local res = StringRef::NewFromUtf16(vm, (char16_t*)data, length); + if (length == 1) { + buffer[0] = '\0'; + } else if (length != 0) { + int count = res->WriteUtf16(buffer, length - 1); + buffer[count] = '\0'; + } + delete[] buffer; + buffer = nullptr; JSNApi::DestroyJSVM(vm); } } diff --git a/test/resource/js_runtime/ohos_test.xml b/test/resource/js_runtime/ohos_test.xml index 948abacfbe..f7635c636a 100755 --- a/test/resource/js_runtime/ohos_test.xml +++ b/test/resource/js_runtime/ohos_test.xml @@ -1679,6 +1679,231 @@