Repository navigation
Labels
bugSquash those bugs
Description
Describe the bug
When constructing a FixedSizeBinaryArray, if the given buffer bytes don't divide evenly by the value_size, we have trailing bytes which can be returned by APIs. For example:
#[test]
fn test123() {
let array = FixedSizeBinaryArray::new(3, vec![0_u8; 10].into(), None);
assert_eq!(array.len(), 3); // 3 * 3 = 9
assert_eq!(array.value_data().len(), 10); // 1 trailing byte
}This test currently passes. This can be confusing, and can lead to bugs in other APIs. For example:
arrow-rs/arrow-array/src/builder/fixed_size_binary_builder.rs
Lines 95 to 110 in f1ca38f
| /// Appends all elements in array into the builder. | |
| pub fn append_array(&mut self, array: &FixedSizeBinaryArray) -> Result<(), ArrowError> { | |
| if self.value_length != array.value_length() { | |
| return Err(ArrowError::InvalidArgumentError( | |
| "Cannot append FixedSizeBinaryArray with different value length".to_string(), | |
| )); | |
| } | |
| let buffer = array.value_data(); | |
| self.values_builder.extend_from_slice(buffer); | |
| if let Some(validity) = array.nulls() { | |
| self.null_buffer_builder.append_buffer(validity); | |
| } else { | |
| self.null_buffer_builder.append_n_non_nulls(array.len()); | |
| } | |
| Ok(()) | |
| } |
- Lines 102 & 103 assume that all bytes are part of the array; however if we have trailing bytes, these can be appended and corrupt the data of the builder
To Reproduce
No response
Expected behavior
Fix to ensure we strip trailing bytes, so we have a consistent view of only the bytes involved in the array
Additional context
No response
Willingness to contribute
I cannot contribute a fix for this bug at this time
Activity
fix(arrow-array): strip trailing bytes in values data when constructi…