JonSnow1807 opened a new pull request, #54913:
URL: https://github.com/apache/arrow/pull/54913

   ### 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.
   
   * GitHub Issue: #54908
   
   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.
   


-- 
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]

Reply via email to