Mr-Nobody-Anonymous opened a new pull request, #55903:
URL: https://github.com/apache/arrow/pull/55903

   ### Rationale for this change
   
   In `RegisterVectorArraySort` 
(`cpp/src/arrow/compute/kernels/vector_array_sort.cc`), `base.exec_chunked` is 
set to `ArraySortIndicesChunked` for `array_sort_indices` and then reused when 
registering `partition_nth_indices` without resetting `base.exec_chunked`.
   
   When `partition_nth_indices` is called on a `ChunkedArray`, `VectorExecutor` 
dispatches to `ArraySortIndicesChunked`, which casts `ctx->state()` 
(`OptionsWrapper<PartitionNthOptions>`) to `OptionsWrapper<ArraySortOptions>`. 
In debug builds this fails/segfaults via `checked_cast`, and in release builds 
it reads `PartitionNthOptions` as `ArraySortOptions` and runs 
`SortChunkedArray` instead of partitioning.
   
   ### What changes are included in this PR?
   
   - Reset `base.exec_chunked = nullptr` before registering 
`partition_nth_indices` kernels in `RegisterVectorArraySort`, so 
`VectorExecutor::Execute` cleanly returns `Status::Invalid` for `ChunkedArray` 
inputs instead of dispatching to `ArraySortIndicesChunked`.
   - Add a regression test 
(`TestNthToIndicesForIntegral.ChunkedArrayUnsupported`) in 
`cpp/src/arrow/compute/kernels/vector_sort_test.cc`.
   
   ### Are these changes tested?
   
   Yes, added `TestNthToIndicesForIntegral.ChunkedArrayUnsupported` in 
`cpp/src/arrow/compute/kernels/vector_sort_test.cc`.
   
   ### Are there any user-facing changes?
   
   Calling `partition_nth_indices` with a `ChunkedArray` now returns 
`Status::Invalid` ("Vector kernel cannot execute chunkwise and no chunked exec 
function was defined") instead of segfaulting or returning an incorrect result.
   
   **This PR contains a "Critical Fix".** It fixes a crash (segfault in debug 
builds / undefined behavior and wrong results in release builds) when 
`partition_nth_indices` is called on a `ChunkedArray`.
   
   ### Was AI used for this PR?
   
   **PR code and description written by:**
   
   - [x] Human
   - [x] AI
   
   **Reviewed before submission by:**
   
   - [x] Human
   
   * GitHub Issue: #55775


-- 
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]

Reply via email to