mailmindlin opened a new pull request, #12454:
URL: https://github.com/apache/arrow-rs/pull/12454
# Which issue does this PR close?
- Closes #12453
# Rationale for this change
The IPC reader panics on a misaligned input buffer in two cases, rather than
applying `require_alignment`:
1. The offsets of a dense union, in either alignment mode.
2. Any array with a multi-byte buffer, when `require_alignment` and
`skip_validation` are both set.
See the issue for a reproducer. I encountered this bug when trying to decode
from a sliced network buffer.
# What changes are included in this PR?
- Dense union offsets go through a new `create_scalar_buffer`, the
counterpart of `create_array_from_builder` for arrays that aren't built from an
`ArrayDataBuilder`. A misaligned buffer is copied, or with `require_alignment`
is reported with the same error as `ArrayData::validate`.
- `create_array_from_builder` checks alignment itself when validation is
skipped and alignment is required. Alignment depends on the caller's buffer,
not on the encoded data, and the default mode already aligns buffers regardless
of `skip_validation`. The check is one pointer test per buffer.
- `test_misaligned_dense_union` in arrow-flight asserted this panic with
`#[should_panic]` (#10428). It now asserts the error.
# Are these changes tested?
Yes. Two new `StreamDecoder` tests decode dense and sparse unions at each
byte offset in `0..16`, in both alignment modes and with validation on and off.
`test_misaligned_buffers_error` now also runs with validation skipped. All
three fail and panic without the fix.
# Are there any significant user-facing changes?
no
# AI usage disclosure
Claude Code was used to write the fix and tests after I found the bug. I've
reviewed all of it.
--
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]