This is an automated email from the ASF dual-hosted git repository.

liuneng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new a96a09eebd [CH] Fix SIGSEGV on jstring2string #7928
a96a09eebd is described below

commit a96a09eebdc3ef26e141edb519c9eb8dbf8de0a0
Author: LiuNeng <[email protected]>
AuthorDate: Wed Nov 13 13:49:45 2024 +0800

    [CH] Fix SIGSEGV on jstring2string #7928
    
    What changes were proposed in this pull request?
    replace jstring2string implementation, avoid SIGSEGV on getObjectClass
    
    How was this patch tested?
    (Please explain how this patch was tested. E.g. unit tests, integration 
tests, manual tests)
    
    manual tests
---
 cpp-ch/local-engine/local_engine_jni.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/cpp-ch/local-engine/local_engine_jni.cpp 
b/cpp-ch/local-engine/local_engine_jni.cpp
index 24c5950065..2ec0622311 100644
--- a/cpp-ch/local-engine/local_engine_jni.cpp
+++ b/cpp-ch/local-engine/local_engine_jni.cpp
@@ -74,22 +74,14 @@ static DB::ColumnWithTypeAndName 
getColumnFromColumnVector(JNIEnv * /*env*/, job
     return block->getByPosition(column_position);
 }
 
-static std::string jstring2string(JNIEnv * env, jstring jStr)
-{
-    if (!jStr)
-        return "";
-
-    const jclass string_class = env->GetObjectClass(jStr);
-    const jmethodID get_bytes = env->GetMethodID(string_class, "getBytes", 
"(Ljava/lang/String;)[B");
-    auto * const string_jbytes
-        = static_cast<jbyteArray>(local_engine::safeCallObjectMethod(env, 
jStr, get_bytes, env->NewStringUTF("UTF-8")));
-    SCOPE_EXIT({
-        env->DeleteLocalRef(string_jbytes);
-        env->DeleteLocalRef(string_class);
-    });
-
-    const auto string_jbytes_a = local_engine::getByteArrayElementsSafe(env, 
string_jbytes);
-    return {reinterpret_cast<char *>(string_jbytes_a.elems()), 
static_cast<size_t>(string_jbytes_a.length())};
+static std::string jstring2string(JNIEnv * env, jstring string)
+{
+    if (string == nullptr)
+        return std::string();
+    const char * chars = env->GetStringUTFChars(string, nullptr);
+    std::string ret(chars);
+    env->ReleaseStringUTFChars(string, chars);
+    return ret;
 }
 
 extern "C" {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to