aloneangel45 opened a new pull request, #12410:
URL: https://github.com/apache/arrow-rs/pull/12410

   # Which issue does this PR close?
   
   - Closes #12409
   
   # Rationale for this change
   
   `FixedSizeBinaryArray::try_new` and `FixedSizeBinaryArray::try_new_with_len` 
allow constructing an array from a `Buffer` with trailing remainder bytes 
(tested in `test_constructors` for a 10-byte buffer with `value_length = 3` 
yielding `len() == 3`), but stored the unsliced `Buffer`. As a result, 
`FixedSizeBinaryArray::value_data()` and `values()` exposed trailing bytes past 
`len * value_size`, causing callers such as 
`FixedSizeBinaryBuilder::append_array` to append extra non-element bytes and 
shift subsequent elements.
   
   # What changes are included in this PR?
   
   - Update `FixedSizeBinaryArray::try_new_with_len` in 
`arrow-array/src/array/fixed_size_binary_array.rs` to slice `values` to `0..len 
* value_size` whenever `values.len() > len * value_size`, matching the 
invariant already maintained by `From<ArrayData>`, `slice()`, and 
`new_unchecked()`.
   - Add unit tests covering `value_data()`, `values()`, `to_data()`, 
`into_parts()`, and `FixedSizeBinaryBuilder::append_array` when the source 
`FixedSizeBinaryArray` is constructed from a buffer containing trailing bytes.
   
   # Are these changes tested?
   
   Yes. Added unit tests `test_try_new_strips_trailing_bytes` 
(`arrow-array/src/array/fixed_size_binary_array.rs`) and 
`test_fixed_size_binary_builder_append_array_trailing_bytes` 
(`arrow-array/src/builder/fixed_size_binary_builder.rs`) covering construction 
with trailing buffer bytes and appending into `FixedSizeBinaryBuilder`, and ran 
`arrow-array` and `arrow-select` tests alongside `rustfmt` and `clippy`.
   
   # Are there any significant user-facing changes?
   
   No. `FixedSizeBinaryArray::value_data()`, `values()`, `to_data()`, and 
`into_parts()` now expose only the `len * value_size` bytes belonging to the 
array rather than trailing buffer padding bytes.
   
   # AI usage disclosure
   
   An LLM coding assistant helped inspect callers, draft the fix and unit 
tests, and run local `cargo` verification, with all changes reviewed and 
verified before submission.


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