Skip to content

GH-54937: [C++] Fix DenseUnionArray::Make for sliced type_ids and value_offsets arrays - #54940

Closed
JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:gh-dense-union-sliced-offsets
Closed

JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:gh-dense-union-sliced-offsets

Conversation

@JonSnow1807

@JonSnow1807 JonSnow1807 commented Oct 22, 2026 •

Copy link
Copy Markdown

Rationale for this change

DenseUnionArray::Make used type_ids.offset() as the union offset for both the type ids and the value offsets buffers, and never checked the length of value_offsets. With a value_offsets array that is sliced differently from type_ids the union reads value offsets from the wrong positions (and ValidateFull cannot tell), and a too-short value_offsets array is accepted. See GH-54937; same root cause as GH-54907 (#54938).

What changes are included in this PR?

  • DenseUnionArray::Make returns Invalid when value_offsets is shorter than type_ids. A longer value_offsets array is still tolerated (only the first len(type_ids) offsets are used), since existing callers rely on that.
  • When type_ids or value_offsets is sliced, its buffer is sliced (zero-copy) to the logical window and the union is built with offset 0. Unsliced inputs keep using the original buffers.
  • Regression test TestUnionArrayFactories.TestMakeDenseSliced.

Are these changes tested?

Yes. The new test fails on main (sliced value_offsets yields [10, 20] instead of [20, 30], and the short value_offsets array is accepted) and passes with the fix. arrow-array-test, arrow-ipc-read-write-test, arrow-scalar-test and arrow-compute-scalar-type-test pass locally (Debug, ASan/UBSan).

Are there any user-facing changes?

DenseUnionArray::Make now returns Invalid when value_offsets is shorter than type_ids, and the resulting array has offset 0 instead of type_ids.offset().

AI usage disclosure: Claude Code assisted with investigating the root cause, preparing the implementation, and developing the regression test. I reviewed the changes and am responsible for their correctness.

…nd value_offsets arrays

DenseUnionArray::Make used type_ids.offset() as the offset of the union
array for both the type ids and the value offsets buffers, and never
checked the length of value_offsets. With a value_offsets array sliced
differently from type_ids the union read value offsets from the wrong
positions (which ValidateFull cannot detect), and a value_offsets array
shorter than type_ids was accepted.

Reject value_offsets arrays shorter than type_ids, slice both buffers to
their logical windows (zero-copy) when the inputs are sliced, and build
the union with offset 0. Unsliced inputs keep using the original buffers.
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #54937 has been automatically assigned in GitHub to PR creator.

@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically closed because you currently have 4 open pull requests, which is more than the limit of 3.

Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale.

Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one.

See also:

@github-actions github-actions Bot closed this Oct 22, 2026
@github-actions github-actions Bot added the awaiting review Awaiting review label Oct 22, 2026
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.

1 participant