Skip to content

GH-51018: [C++] Fix indices_nonzero segfault on chunkless ChunkedArray - #51021

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/nonzero-zero-chunks-51018
Open

GH-51018: [C++] Fix indices_nonzero segfault on chunkless ChunkedArray#51021
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/nonzero-zero-chunks-51018

Conversation

@waterWang

@waterWang waterWang commented Aug 28, 2026

Copy link
Copy Markdown

Rationale for this change

pyarrow.compute.indices_nonzero() segfaults (SIGSEGV) on a ChunkedArray
with zero chunks — the shape produced by filtering a table to no rows or
slicing zero rows. Reproduced on pyarrow 18.1.0 through 25.0.1. A zero-length
Array and a ChunkedArray holding one empty chunk both work; only the
chunkless case crashes.

What changes are included in this PR?

IndicesNonZeroExecChunked builds a std::vector<ArraySpan> from the chunks;
for a zero-chunk array that vector is empty. DoNonZero unconditionally
dereferenced arrays[0].type, an out-of-bounds vector access. Guard DoNonZero
so an empty chunk vector returns an empty result, consistent with the other
empty-input paths.

Are these changes tested?

Yes — added a zero-chunk case to TestIndicesNonZero.IndicesNonZero that
asserts indices_nonzero on ChunkedArray({}, type) returns [] for every
numeric type. The crash reproduces locally on pyarrow 25.0.1 (SIGSEGV); with
the fix the same call returns an empty array.

…edArray

Calling indices_nonzero on a ChunkedArray with zero chunks (e.g. the shape
produced by filtering a table down to no rows) segfaulted. IndicesNonZeroExecChunked
built an empty vector of ArraySpans, and DoNonZero unconditionally dereferenced
arrays[0].type, performing an out-of-bounds vector access.

Guard DoNonZero so an empty chunk vector yields an empty result, consistent with
the zero-length Array and single-empty-chunk cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Python] pyarrow.compute.indices_nonzero segfaults on a ChunkedArray with zero chunks

1 participant