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

fix: Remove unsafe uses of from_raw_parts from crc32 and murmur hash functions #554

Closed

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Jun 11, 2024

Which issue does this PR close?

Part of #507

Rationale for this change

Remove unsafe uses of from_raw_parts. This code fails in a debug assertion when we upgrade to Rust 1.78.

This fix is copied from #546

What changes are included in this PR?

How are these changes tested?

@andygrove andygrove requested a review from sunchao June 11, 2024 13:25
Comment on lines -48 to -49
let data_bytes_64 =
std::slice::from_raw_parts(&data_bytes[0..len_64] as *const [u8] as *const u64, len / 8);
Copy link
Member Author

Choose a reason for hiding this comment

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

This violates a precondition for from_raw_parts because data_bytes is not guaranteed to be correctly aligned for u64.

Comment on lines -109 to -112
let bytes_u32: &[u32] = std::slice::from_raw_parts(
&bytes[0..num_words * u32_num_bytes] as *const [u8] as *const u32,
num_words,
);
Copy link
Member Author

Choose a reason for hiding this comment

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

This violates a precondition for from_raw_parts because bytes is not guaranteed to be correctly aligned for u32.

@andygrove andygrove requested a review from viirya June 11, 2024 13:29
@andygrove andygrove marked this pull request as draft June 11, 2024 21:46
@andygrove
Copy link
Member Author

Moving to draft until I have criterion benchmarks in place

@andygrove
Copy link
Member Author

I found out that none of this code is actually used in Comet, so I am deleting it in #561

@andygrove andygrove closed this Jun 12, 2024
@andygrove andygrove deleted the remove-unsafe-from-raw-parts-hash branch December 3, 2024 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant