-
Notifications
You must be signed in to change notification settings - Fork 759
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
Consider Vec::from_iter in Buffer::from_iter #4937
Comments
MutableBuffer uses an aligned allocator, with an alignment exceeding that of any ArrowNativeType, so this should be fine. That being said we can probably eliminate this unsafe, without regressing performance |
@tustvold thanks for the response. Then, why does it still panic? |
Because the Buffer::slice which comes after in the test is shifting it so that Buffer is no longer aligned, but unlike MutableBuffer, Buffer has no alignment restrictions so this is safe For context these APIs exist to accommodate zero-copy data exchange over FFI and IPC, along with custom allocators and over-alignment for SIMD, they're definitely on the funky end and it'd be great to get more eyes on what they are doing |
Fair enough. Thanks! |
Buffer::from_iter
Yes. I just realized these two lines after discussion with you 😂 arrow-rs/arrow-buffer/src/buffer/mutable.rs Lines 72 to 73 in 90bc5ec
|
I've taken the liberty of updating the issue title to rephrase this into an enhancement proposal. I think this should be relatively straightforward, and less unsafe is always a good thing, the major task would be making sure it doesn't regress anything |
The source of unsoundness
Hi, we are the Rust researchers from SunLab. Recently, we are trying to test our static analysis tool and find the potential unsound function in the package of
arrow-buffer
:arrow-rs/arrow-buffer/src/buffer/immutable.rs
Lines 417 to 432 in 90bc5ec
In line 429, when the mutable pointer is cast to generic type, it is actually casting from
u8
to any-aligned type which could create a misaligned pointer. However, it seems that the programmers are also aware of the bugs in the test case:arrow-rs/arrow-buffer/src/buffer/scalar.rs
Lines 224 to 231 in 90bc5ec
Here,
u8
is cast toi32
and create a misaligned pointer and panic occurs.We consider that it should not happen in safe API anyway based on the safety requirement of
ptr.write()
. The problem could be fixed by passing the layout ofelement
to allocate the memory.We would love to have more discussion, and please correct if we are wrong.
The text was updated successfully, but these errors were encountered: