Skip to content

GH-54908: [C++] Reject non-empty union arrays with missing type ids or offsets buffers - #54913

Open
JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:gh-54908-union-validate-missing-buffers
Open

JonSnow1807 wants to merge 1 commit into
apache:mainfrom
JonSnow1807:gh-54908-union-validate-missing-buffers

Conversation

@JonSnow1807

Copy link
Copy Markdown

Rationale for this change

Validate() accepts a non-empty union array whose type ids buffer is null, or a dense union array whose offsets buffer is null. ValidateFull() then reads data.GetValues<int8_t>(1) / data.GetValues<int32_t>(2) unconditionally and segfaults (reproduced with the Python snippet from the issue: all three cases exit with SIGSEGV).

What changes are included in this PR?

ValidateArrayImpl::Visit(const UnionType&) now returns Status::Invalid when the array is non-empty and the type ids buffer is null, or when it is a non-empty dense union and the offsets buffer is null. This mirrors the existing "Non-empty array but offsets are null" check for list and binary types. Empty arrays may still omit these buffers.

Are these changes tested?

Yes. TestSparseUnionArray.ValidateMissingTypeIds and TestDenseUnionArray.ValidateMissingBuffers in array_union_test.cc check that Validate() and ValidateFull() both return Invalid with the new messages, that an array with all buffers present still validates, and that empty arrays without the buffers still validate. Without the fix the new tests fail ("Expected ... to fail with Invalid, but got OK"); with it arrow-array-test passes (1075 passed, 1 skipped, Debug build with ASan/UBSan).

Are there any user-facing changes?

Validate() and ValidateFull() now return an error instead of crashing for these arrays.

AI usage: the fix and the tests were written with an AI coding assistant (Claude Code) under my direction; I reviewed every line and ran the tests locally.

… ids or offsets buffers

Validate() accepted a non-empty union array whose type ids buffer is null,
or a dense union whose offsets buffer is null, and ValidateFull() then
dereferenced the null buffer and crashed. Report such arrays as invalid
instead, like the existing "Non-empty array but offsets are null" check for
list and binary types. Empty arrays may still omit these buffers.
@github-actions

Copy link
Copy Markdown

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

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