Repository navigation
GH-54570: [C++][Compute] Fix segfault casting null list with empty child to fixed_size_list - #54574
Open
ShivanshhhG wants to merge 1 commit into
Open
ShivanshhhG wants to merge 1 commit into
ShivanshhhG wants to merge 1 commit into
Conversation
…pty child to fixed_size_list When casting a ListArray or LargeListArray to FixedSizeListArray, if an array contains only null lists with an empty child array, cast_values->length is 0. Previously, BuildTakeIndices populated index 0 for null slots, and Take was called with TakeOptions::NoBoundsCheck(), dereferencing an unallocated child buffer and causing a segmentation fault. This commit resolves the issue by: 1. Handling empty child values (cast_values->length == 0) directly using MakeArrayOfNull rather than attempting Take. 2. Emitting null indices (builder.UnsafeAppendNull()) for null list slots in BuildTakeIndices instead of index 0. 3. Adding regression tests for casting null lists with empty children and unallocated buffers to FixedSizeList. Fixes: apache#54570 Signed-off-by: SHIVANSH-ux-ys <singaser78@gmail.com>
|
|
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
When casting a
ListArray,LargeListArray, orListViewArraytoFixedSizeListArray, 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 Polarsto_arrow()),cast_values->lengthis 0.Previously,
BuildTakeIndicespopulated index0for every null slot (builder.UnsafeAppend(0)). WhenTakewas called withTakeOptions::NoBoundsCheck(), it attempted to access index 0 on an empty child array whose buffers may be null or unallocated, dereferencing a null pointer inFixedWidthTakeImpland causing a segmentation fault (GH-54570).What changes are included in this PR?
cast_values->length == 0, bypassTakeentirely and directly create the output child array usingMakeArrayOfNull(child_type, in_array.length * list_size, ctx->memory_pool()).BuildTakeIndices, emit null indices (builder.UnsafeAppendNull()) for null list slots instead of index0.cpp/src/arrow/compute/kernels/scalar_cast_test.ccverifying that casting null lists with empty children (including unallocated child buffers) toFixedSizeListsucceeds and produces the expected null list array.Are these changes tested?
Yes, unit tests added to
cpp/src/arrow/compute/kernels/scalar_cast_test.ccunderTEST(Cast, ListToFSL).Are there any user-facing changes?
No (fixes crash/segfault on valid spec-compliant input).