From 0adafe98a67bb4789372ca237ee62b8d790c80af Mon Sep 17 00:00:00 2001 From: lhc Date: Tue, 15 Jul 2025 20:39:09 +0800 Subject: [PATCH 1/2] Add exception check Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICMJSC?from=project-issue Signed-off-by: lhc Change-Id: Id4924b9c162abd14a551989d069bba3b2a5c8674 --- ecmascript/builtins/builtins_arraybuffer.cpp | 4 ---- ecmascript/builtins/builtins_arraybuffer.h | 4 ---- ecmascript/napi/jsnapi_expo.cpp | 4 ++++ .../allocatearraybuffer/allocatearraybuffer.js | 17 ----------------- .../allocatearraybuffer/expect_output.txt | 2 -- 5 files changed, 4 insertions(+), 27 deletions(-) diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index 44ca29e3d4..a4bf0f7a52 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -229,10 +229,6 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J if (byteLength > INT_MAX) { THROW_RANGE_ERROR_AND_RETURN(thread, "Out of range", JSTaggedValue::Exception()); } - uint64_t totalNativeSize = static_cast(thread->GetNativeAreaAllocator()->GetArrayBufferNativeSize()); - if (UNLIKELY(totalNativeSize > MAX_NATIVE_SIZE_LIMIT)) { - THROW_RANGE_ERROR_AND_RETURN(thread, NATIVE_SIZE_OUT_OF_LIMIT_MESSAGE, JSTaggedValue::Exception()); - } uint32_t arrayByteLength = static_cast(byteLength); JSHandle arrayBuffer(obj); // 6. Set obj’s [[ArrayBufferData]] internal slot to block. diff --git a/ecmascript/builtins/builtins_arraybuffer.h b/ecmascript/builtins/builtins_arraybuffer.h index 1a0f5ff025..2fdc5d4369 100644 --- a/ecmascript/builtins/builtins_arraybuffer.h +++ b/ecmascript/builtins/builtins_arraybuffer.h @@ -113,10 +113,6 @@ public: DataViewType type, bool littleEndian); static void *GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset = 0); -protected: - static constexpr uint64_t MAX_NATIVE_SIZE_LIMIT = 4_GB; - static constexpr char const *NATIVE_SIZE_OUT_OF_LIMIT_MESSAGE = "total array buffer size out of limit(4_GB)"; - private: #define BUILTIN_ARRAY_BUFFER_ENTRY(name, func, length, id) \ base::BuiltinFunctionEntry::Create((name), (BuiltinsArrayBuffer::func), (length), (BUILTINS_STUB_ID(id))), diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index d41f4387f8..9571967dec 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2383,6 +2383,10 @@ Local StringRef::EncodeIntoUint8Array(const EcmaVM *vm) JSHandle obj = TypedArrayHelper::FastCreateTypedArray(thread, thread->GlobalConstants()->GetHandledUint8ArrayString(), length - 1, DataViewType::UINT8); + if (JSNApi::HasPendingException(vm)) { + LOG_ECMA(ERROR) << "JSNapi EncodeIntoUint8Array: Create TypedArray failed"; + return Undefined(vm); + } JSHandle arrayBuffer(thread, JSTypedArray::Cast(*obj)->GetViewedArrayBufferOrByteArray()); JSTaggedValue bufferData = JSHandle::Cast(arrayBuffer)->GetArrayBufferData(); void *buffer = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); diff --git a/test/moduletest/allocatearraybuffer/allocatearraybuffer.js b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js index 9475338d24..0e5a07d549 100644 --- a/test/moduletest/allocatearraybuffer/allocatearraybuffer.js +++ b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js @@ -40,23 +40,6 @@ for (let i = 0; i < v32.length; i++) { const v36 = this.Atomics; print(v36.and(v32, this, v36)); -function f() { - let a1 = new ArrayBuffer(1025*1025*1025); - let a2 = new ArrayBuffer(1025*1025*1025); - let a3 = new ArrayBuffer(1025*1025*1025); - let a4 = new ArrayBuffer(1025*1025*1025); - try { - let arr = new ArrayBuffer(10); - print(a1.byteLength + a2.byteLength + a3.byteLength + a4.byteLength + arr.byteLength); - } catch (error) { - print(error); - } -} -f(); -ArkTools.forceFullGC(); -f(); -ArkTools.forceFullGC(); - function SendableArrayBufferTest() { try { const o1 = {}; diff --git a/test/moduletest/allocatearraybuffer/expect_output.txt b/test/moduletest/allocatearraybuffer/expect_output.txt index 6b6c6971a7..5fd9e962a3 100644 --- a/test/moduletest/allocatearraybuffer/expect_output.txt +++ b/test/moduletest/allocatearraybuffer/expect_output.txt @@ -14,6 +14,4 @@ undefined NaN 1 -RangeError: total array buffer size out of limit(4_GB) -RangeError: total array buffer size out of limit(4_GB) TypeError: shared ctor cannot assign unshared newTarget \ No newline at end of file -- Gitee From 752f4ddc0ebe4d878ae4172b4e81161049ae6a49 Mon Sep 17 00:00:00 2001 From: lhc Date: Thu, 17 Jul 2025 09:49:33 +0800 Subject: [PATCH 2/2] Resolve build issues Issues: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICMV0P?from=project-issue Signed-off-by: lhc Change-Id: I0bf5b566ba5fca2a97b32a8d0fca1ef273628990 --- compiler_service/test/BUILD.gn | 18 +++++++++--------- .../aotcompilerargsprepare_fuzzer/BUILD.gn | 1 - .../compilerinterfacestub_fuzzer/BUILD.gn | 1 - .../aotcompilerargshandler_unit/BUILD.gn | 1 - .../unittest/aotcompilerclient_unit/BUILD.gn | 1 - .../aotcompilererrorutils_unit/BUILD.gn | 1 - .../unittest/aotcompilerimpl_unit/BUILD.gn | 1 - .../unittest/aotcompilerproxy_unit/BUILD.gn | 1 - .../unittest/aotcompilerservice_unit/BUILD.gn | 1 - .../unittest/aotcompilerstub_unit/BUILD.gn | 1 - 10 files changed, 9 insertions(+), 18 deletions(-) diff --git a/compiler_service/test/BUILD.gn b/compiler_service/test/BUILD.gn index 933eb0eae8..f457e8ad7f 100644 --- a/compiler_service/test/BUILD.gn +++ b/compiler_service/test/BUILD.gn @@ -14,20 +14,20 @@ group("compiler_service_unittest") { testonly = true deps = [ - #"unittest/aotcompilerargshandler_unit:AotCompilerArgsHandlerUnitTest", - #"unittest/aotcompilerclient_unit:AotCompilerClientUnitTest", - #"unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest", - #"unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest", - #"unittest/aotcompilerproxy_unit:AotCompilerProxyUnitTest", - #"unittest/aotcompilerservice_unit:AotCompilerServiceUnitTest", - #"unittest/aotcompilerstub_unit:AotCompilerStubUnitTest", + "unittest/aotcompilerargshandler_unit:AotCompilerArgsHandlerUnitTest", + "unittest/aotcompilerclient_unit:AotCompilerClientUnitTest", + "unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest", + "unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest", + "unittest/aotcompilerproxy_unit:AotCompilerProxyUnitTest", + "unittest/aotcompilerservice_unit:AotCompilerServiceUnitTest", + "unittest/aotcompilerstub_unit:AotCompilerStubUnitTest", ] } group("compiler_service_fuzztest") { testonly = true deps = [ - #"fuzztest/aotcompilerargsprepare_fuzzer:AotCompilerArgsPrepareFuzzTest", - #"fuzztest/compilerinterfacestub_fuzzer:CompilerInterfaceStubFuzzTest", + "fuzztest/aotcompilerargsprepare_fuzzer:AotCompilerArgsPrepareFuzzTest", + "fuzztest/compilerinterfacestub_fuzzer:CompilerInterfaceStubFuzzTest", ] } diff --git a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn index 6270be63b0..59e3407cf1 100644 --- a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn @@ -31,7 +31,6 @@ ohos_fuzztest("AotCompilerArgsPrepareFuzzTest") { ] configs = [ "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn index 9fe719bfbe..4f40c24150 100644 --- a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn @@ -31,7 +31,6 @@ ohos_fuzztest("CompilerInterfaceStubFuzzTest") { ] configs = [ "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn index 328a9661ac..1a8f27f921 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerArgsHandlerUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn index 3c928442ca..5299c50d77 100644 --- a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerClientUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn index 0dc8b62f61..0648707e85 100644 --- a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerErrorUtilsUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn index 544ca59542..5ac62e3f41 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerImplUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn index 7d92ac28ac..d530ab7299 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerProxyUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn index c8517a6fe2..9db3234f84 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerServiceUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn index c451bf646a..a417cf0a97 100644 --- a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerStubUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ -- Gitee