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

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new 13085d78b fix: avoid panic caused by close null handle of parquet 
reader (#1604)
13085d78b is described below

commit 13085d78bc513365378018a4d2327f2bcc97d6f7
Author: Zhen Wang <[email protected]>
AuthorDate: Fri Apr 4 01:54:24 2025 +0800

    fix: avoid panic caused by close null handle of parquet reader (#1604)
---
 native/core/src/parquet/mod.rs                              |  4 ++--
 .../src/test/scala/org/apache/comet/CometNativeSuite.scala  | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/native/core/src/parquet/mod.rs b/native/core/src/parquet/mod.rs
index d522a83aa..8a51fc2cf 100644
--- a/native/core/src/parquet/mod.rs
+++ b/native/core/src/parquet/mod.rs
@@ -586,7 +586,7 @@ pub extern "system" fn 
Java_org_apache_comet_parquet_Native_closeColumnReader(
 ) {
     try_unwrap_or_throw(&env, |_| {
         unsafe {
-            let ctx = handle as *mut Context;
+            let ctx = get_context(handle)?;
             let _ = Box::from_raw(ctx);
         };
         Ok(())
@@ -805,7 +805,7 @@ pub extern "system" fn 
Java_org_apache_comet_parquet_Native_closeRecordBatchRead
 ) {
     try_unwrap_or_throw(&env, |_| {
         unsafe {
-            let ctx = handle as *mut BatchContext;
+            let ctx = get_batch_context(handle)?;
             let _ = Box::from_raw(ctx);
         };
         Ok(())
diff --git a/spark/src/test/scala/org/apache/comet/CometNativeSuite.scala 
b/spark/src/test/scala/org/apache/comet/CometNativeSuite.scala
index 6ca38e831..2ff38eae8 100644
--- a/spark/src/test/scala/org/apache/comet/CometNativeSuite.scala
+++ b/spark/src/test/scala/org/apache/comet/CometNativeSuite.scala
@@ -50,4 +50,17 @@ class CometNativeSuite extends CometTestBase {
     }
     assert(exception.getMessage contains "java.lang.NullPointerException")
   }
+
+  test("handling NPE when closing null handle of parquet reader") {
+    assert(NativeBase.isLoaded)
+    val exception1 = intercept[NullPointerException] {
+      parquet.Native.closeRecordBatchReader(0)
+    }
+    assert(exception1.getMessage contains "null batch context handle")
+
+    val exception2 = intercept[NullPointerException] {
+      parquet.Native.closeColumnReader(0)
+    }
+    assert(exception2.getMessage contains "null context handle")
+  }
 }


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

Reply via email to