Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory alignment error in RawPtrBox::new #2882

Closed
viirya opened this issue Oct 16, 2022 · 3 comments · Fixed by #2883
Closed

Memory alignment error in RawPtrBox::new #2882

viirya opened this issue Oct 16, 2022 · 3 comments · Fixed by #2883
Labels
arrow Changes to the arrow crate bug

Comments

@viirya
Copy link
Member

viirya commented Oct 16, 2022

Describe the bug

When we read array data from IPC, IPC reader basically shares the same memory allocation between Buffers across arrays. These Buffers are just separate slices of an original Buffer.

But this possibly causes memory alignment check error in RawPtrBox::new where an assert verifies if the given pointer is aligned with type T. The alignment offset is computed based on original memory allocation, not these slices.

For example, there are three slices.

let x = [5u8, 6u8, 7u8, 8u8, 9u8];
let y = &x[0..x.len() -1];
let z = [5u8, 6u8, 7u8, 8u8];

Then we compute their alignment offset by:

let ptr = x.as_ptr() as *const u8;
let offset = ptr.align_offset(align_of::<u16>());

The offset of x and y are both 1, and the offset of z is 0.

To Reproduce

Just run cargo test read_generated_files_014 on M1 Macbook. Got:

running 1 test
thread 'read_generated_files_014' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `0`: memory is not aligned', arrow-array/src/raw_pointer.rs:40:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test read_generated_files_014 ... FAILED

failures:

failures:
    read_generated_files_014

Expected behavior

Additional context

@tustvold
Copy link
Contributor

What is the alignment requirement for i128 on an M1 mac, on x86 it is 8 bytes, which is what is guaranteed by the IPC format?

The error message would suggest the buffer is 8 byte aligned, but that this is insufficient for whatever type is being handled.

My hunch is arm requires 16-byte alignment for i128, and following #2857 we are only just now seeing this. I suspect for this case we will need to copy the buffer.

@viirya
Copy link
Member Author

viirya commented Oct 16, 2022

Yes, on M1 Macbook, the alignment for i128 is 16 bytes.

@alamb
Copy link
Contributor

alamb commented Oct 28, 2022

label_issue.py automatically added labels {'arrow'} from #2883

@alamb alamb added the arrow Changes to the arrow crate label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants