You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "crepererum (via GitHub)" <gi...@apache.org> on 2023/08/11 11:11:36 UTC

[GitHub] [arrow-rs] crepererum commented on a diff in pull request #4681: Validate ArrayData Buffer Alignment and Automatically Align IPC buffers (#4255)

crepererum commented on code in PR #4681:
URL: https://github.com/apache/arrow-rs/pull/4681#discussion_r1291214491


##########
arrow-data/src/data.rs:
##########
@@ -736,17 +753,25 @@ impl ArrayData {
             self.buffers.iter().zip(layout.buffers.iter()).enumerate()
         {
             match spec {
-                BufferSpec::FixedWidth { byte_width } => {
-                    let min_buffer_size = len_plus_offset
-                        .checked_mul(*byte_width)
-                        .expect("integer overflow computing min buffer size");
+                BufferSpec::FixedWidth {
+                    byte_width,
+                    alignment,
+                } => {
+                    let min_buffer_size = len_plus_offset.saturating_mul(*byte_width);
 
                     if buffer.len() < min_buffer_size {
                         return Err(ArrowError::InvalidArgumentError(format!(
                             "Need at least {} bytes in buffers[{}] in array of type {:?}, but got {}",
                             min_buffer_size, i, self.data_type, buffer.len()
                         )));
                     }
+
+                    if buffer.as_ptr().align_offset(*alignment) != 0 {
+                        return Err(ArrowError::InvalidArgumentError(format!(
+                            "Misaligned buffers[{i}] in array of type {:?}, expected {alignment}",

Review Comment:
   I think it would be helpful for debugging to include the actual alignment in addition to the expected value.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org