From bd411bb9479e6c4343bbf327fd65a1045c69406d Mon Sep 17 00:00:00 2001 From: Suraj Suthar Date: Tue, 17 Nov 2026 11:06:31 +0530 Subject: [PATCH 1/2] fix(arrow-array): FixedSizeBinaryBuilder ccepts values whose length differs from value_length by a multiple of 2^32 --- arrow-array/src/builder/fixed_size_binary_builder.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arrow-array/src/builder/fixed_size_binary_builder.rs b/arrow-array/src/builder/fixed_size_binary_builder.rs index 70f0dde26d8e..44c0fdad80c3 100644 --- a/arrow-array/src/builder/fixed_size_binary_builder.rs +++ b/arrow-array/src/builder/fixed_size_binary_builder.rs @@ -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(), @@ -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 } } @@ -210,6 +210,13 @@ mod tests { assert_eq!(b"world", array.value(5)); } + #[test] + fn test_fixed_size_binary_builder_rejects_wrapped_length() { + let mut b = FixedSizeBinaryBuilder::new(1); + let big = vec![0u8; (1usize << 32) + 1]; + assert!(b.append_value(&big).is_err()); + } + #[test] fn test_fixed_size_binary_builder_finish_cloned() { let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 5); From b196065bed8e93eb2137019c84b20619556ff988 Mon Sep 17 00:00:00 2001 From: Suraj Suthar Date: Wed, 18 Nov 2026 10:43:55 +0530 Subject: [PATCH 2/2] added size wrap around fixedsizedbindic and run added test config to only run on 64bit machine --- arrow-array/src/builder/fixed_size_binary_builder.rs | 5 ++++- .../src/builder/fixed_size_binary_dictionary_builder.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arrow-array/src/builder/fixed_size_binary_builder.rs b/arrow-array/src/builder/fixed_size_binary_builder.rs index 44c0fdad80c3..83dace534a57 100644 --- a/arrow-array/src/builder/fixed_size_binary_builder.rs +++ b/arrow-array/src/builder/fixed_size_binary_builder.rs @@ -211,10 +211,13 @@ mod tests { } #[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]; - assert!(b.append_value(&big).is_err()); + let err = b.append_value(&big).unwrap_err(); + assert!(matches!(err, ArrowError::InvalidArgumentError(_))); } #[test] diff --git a/arrow-array/src/builder/fixed_size_binary_dictionary_builder.rs b/arrow-array/src/builder/fixed_size_binary_dictionary_builder.rs index 5ee8b05a0ed8..0c12c09a78af 100644 --- a/arrow-array/src/builder/fixed_size_binary_dictionary_builder.rs +++ b/arrow-array/src/builder/fixed_size_binary_dictionary_builder.rs @@ -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 { - 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, @@ -256,7 +256,7 @@ where value: impl AsRef<[u8]>, count: usize, ) -> Result { - 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,