Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions arrow-array/src/builder/fixed_size_binary_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FixedSizeBinaryBuilder {
/// distinct value element.
#[inline]
pub fn append_value(&mut self, value: impl AsRef<[u8]>) -> Result<(), ArrowError> {
if self.value_length != value.as_ref().len() as i32 {
if value.as_ref().len() != self.value_length as usize {
Err(ArrowError::InvalidArgumentError(
"Byte slice does not have the same length as FixedSizeBinaryBuilder value lengths"
.to_string(),
Expand Down Expand Up @@ -146,7 +146,7 @@ impl FixedSizeBinaryBuilder {
}
/// Returns the total memory capacity in bytes currently
pub fn capacity(&self) -> usize {
self.values_builder.capacity() + self.null_buffer_builder.allocated_size() + 4 // i32
self.values_builder.capacity() + self.null_buffer_builder.allocated_size() + 4 // i32
}
}

Expand Down Expand Up @@ -210,6 +210,16 @@ mod tests {
assert_eq!(b"world", array.value(5));
}

#[test]
#[cfg(target_pointer_width = "64")]
#[ignore = "allocates >4GB to test 32-bit length truncation"]
fn test_fixed_size_binary_builder_rejects_wrapped_length() {
let mut b = FixedSizeBinaryBuilder::new(1);
let big = vec![0u8; (1usize << 32) + 1];
Comment thread
Surajsuthar marked this conversation as resolved.
Resolved
let err = b.append_value(&big).unwrap_err();
assert!(matches!(err, ArrowError::InvalidArgumentError(_)));
}

#[test]
fn test_fixed_size_binary_builder_finish_cloned() {
let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ where
///
/// Returns an error if the new index would overflow the key type.
pub fn append(&mut self, value: impl AsRef<[u8]>) -> Result<K::Native, ArrowError> {
if self.byte_width != value.as_ref().len() as i32 {
if value.as_ref().len() != self.byte_width as usize {
Err(ArrowError::InvalidArgumentError(format!(
"Invalid input length passed to FixedSizeBinaryBuilder. Expected {} got {}",
self.byte_width,
Expand All @@ -256,7 +256,7 @@ where
value: impl AsRef<[u8]>,
count: usize,
) -> Result<K::Native, ArrowError> {
if self.byte_width != value.as_ref().len() as i32 {
if value.as_ref().len() != self.byte_width as usize {
Err(ArrowError::InvalidArgumentError(format!(
"Invalid input length passed to FixedSizeBinaryBuilder. Expected {} got {}",
self.byte_width,
Expand Down
Loading