ShivanshhhG opened a new pull request, #54574: URL: https://github.com/apache/arrow/pull/54574
### Rationale for this change When casting a `ListArray`, `LargeListArray`, or `ListViewArray` to `FixedSizeListArray`, if the input array contains only null lists with an empty child array (which frequently occurs in IPC streams or deserialized batches from tools like Polars `to_arrow()`), `cast_values->length` is 0. Previously, `BuildTakeIndices` populated index `0` for every null slot (`builder.UnsafeAppend(0)`). When `Take` was called with `TakeOptions::NoBoundsCheck()`, it attempted to access index 0 on an empty child array whose buffers may be null or unallocated, dereferencing a null pointer in `FixedWidthTakeImpl` and causing a segmentation fault (GH-54570). ### What changes are included in this PR? 1. If `cast_values->length == 0`, bypass `Take` entirely and directly create the output child array using `MakeArrayOfNull(child_type, in_array.length * list_size, ctx->memory_pool())`. 2. In `BuildTakeIndices`, emit null indices (`builder.UnsafeAppendNull()`) for null list slots instead of index `0`. 3. Add regression tests in `cpp/src/arrow/compute/kernels/scalar_cast_test.cc` verifying that casting null lists with empty children (including unallocated child buffers) to `FixedSizeList` succeeds and produces the expected null list array. ### Are these changes tested? Yes, unit tests added to `cpp/src/arrow/compute/kernels/scalar_cast_test.cc` under `TEST(Cast, ListToFSL)`. ### Are there any user-facing changes? No (fixes crash/segfault on valid spec-compliant input). * GitHub Issue: #54570 -- 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]
