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

chore: Remove unsafe use of from_raw_parts in Parquet decoder #549

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Changes from 5 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
10 changes: 4 additions & 6 deletions core/src/parquet/read/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,21 @@ macro_rules! make_int_variant_impl {

while num - i >= 32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this loop is effectively not needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I combined the two loops into one. I explained more in #549 (comment)

unsafe {
let in_slice = std::slice::from_raw_parts(in_ptr, 32);
Copy link
Member Author

@andygrove andygrove Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsafe because there is no guarantee that the buffer is properly aligned for u32 type (in_ptr is defined earier as let mut in_ptr = &src_data[src_offset..] as *const [u8] as *const u8 as *const u32;).


for n in 0..32 {
for _ in 0..32 {
copy_nonoverlapping(
in_slice[n..].as_ptr() as *const $native_ty,
&src_data[src_offset..] as *const [u8] as *const u8
as *const $native_ty,
&mut dst_slice[dst_offset] as *mut u8 as *mut $native_ty,
1,
);
i += 1;
src_offset += 4;
dst_offset += $type_size;
}
in_ptr = in_ptr.offset(32);
}
}

src_offset += i * 4;

(0..(num - i)).for_each(|_| {
unsafe {
copy_nonoverlapping(
Expand Down
Loading