Copilot commented on code in PR #12211:
URL: https://github.com/apache/gluten/pull/12211#discussion_r3433573658
##########
cpp/core/jni/JniWrapper.cc:
##########
@@ -1476,6 +1510,31 @@ JNIEXPORT void JNICALL
Java_org_apache_gluten_vectorized_ColumnarBatchSerializer
JNI_METHOD_END()
}
+JNIEXPORT jlong JNICALL
+Java_org_apache_gluten_vectorized_ColumnarBatchSerializerJniWrapper_deserializeWithProjection(
// NOLINT
+ JNIEnv* env,
+ jobject wrapper,
+ jlong serializerHandle,
+ jbyteArray data,
+ jintArray requestedCols) {
+ JNI_METHOD_START
+ auto ctx = getRuntime(env, wrapper);
+ auto serializer =
ObjectStore::retrieve<ColumnarBatchSerializer>(serializerHandle);
+ GLUTEN_DCHECK(serializer != nullptr, "ColumnarBatchSerializer cannot be
null");
+ int32_t size = env->GetArrayLength(data);
+ auto safeData = getByteArrayElementsSafe(env, data);
+ // null requestedCols → all columns (nullopt); non-null (including int[0]) →
selection.
+ std::optional<std::vector<int32_t>> requestedOpt;
+ if (requestedCols != nullptr) {
+ jsize nCols = env->GetArrayLength(requestedCols);
+ auto safeCols = getIntArrayElementsSafe(env, requestedCols);
+ requestedOpt = std::vector<int32_t>(safeCols.elems(), safeCols.elems() +
nCols);
+ }
Review Comment:
In deserializeWithProjection, constructing
`std::vector<int32_t>(safeCols.elems(), safeCols.elems() + nCols)` is undefined
behavior when `nCols == 0` because `safeCols.elems()` may legally be a null
pointer for an empty `jintArray` (pointer arithmetic on nullptr is UB). This
can be hit for the V3 zero-column projection path (`count(*)`) where Scala
passes `Array.empty[Int]`.
Handle the empty-array case explicitly before doing pointer arithmetic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]