You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2024/06/09 14:12:19 UTC
[PR] Upgrade to Rust 1.78 and fix issues in unsafe code [datafusion-comet]
andygrove opened a new pull request, #546:
URL: https://github.com/apache/datafusion-comet/pull/546
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes https://github.com/apache/datafusion-comet/issues/507
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Rust 1.78 has better debug assertions and highlights some bugs in our unsafe code
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
- Fix safety issue in murmur3 hash
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1640030932
##########
core/src/execution/sort.rs:
##########
@@ -159,12 +159,16 @@ where
pos += 1;
}
} else {
- unsafe {
- ptr::copy_nonoverlapping(
- bucket.as_ptr(),
- self.get_unchecked_mut(pos),
- bucket.len(),
- );
+ if !bucket.is_empty() {
Review Comment:
what will happen if this check doesn't satisfy? 🤔
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1640031686
##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -85,11 +85,16 @@ pub(crate) fn spark_compatible_murmur3_hash<T: AsRef<[u8]>>(data: T, seed: u32)
// safety:
// avoid boundary checking in performance critical codes.
// all operations are guaranteed to be safe
+ // data is &[u8] so we do not need to check for proper alignment
unsafe {
- let mut h1 = hash_bytes_by_int(
- std::slice::from_raw_parts(data.get_unchecked(0), len_aligned),
- seed,
- );
+ let mut h1 = if len_aligned > 0 {
Review Comment:
perhaps its time to rename the variable from h1 to something meaningful?
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Upgrade to Rust 1.78 and fix issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1632319699
##########
core/src/parquet/util/hash_util.rs:
##########
@@ -106,16 +108,12 @@ unsafe fn crc32_hash(bytes: &[u8], seed: u32) -> u32 {
let num_words = num_bytes / u32_num_bytes;
num_bytes %= u32_num_bytes;
- let bytes_u32: &[u32] = std::slice::from_raw_parts(
- &bytes[0..num_words * u32_num_bytes] as *const [u8] as *const u32,
- num_words,
- );
Review Comment:
This is unsafe because it does not create a u32-aligned buffer and results in a panic with Rust 1.78
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Upgrade to Rust 1.78 and fix issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1632321812
##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -78,8 +78,12 @@ pub(crate) fn spark_compatible_murmur3_hash<T: AsRef<[u8]>>(data: T, seed: u32)
}
h1
}
+
let data = data.as_ref();
let len = data.len();
+ if len == 0 {
+ return seed;
Review Comment:
I am not sure if this is the correct return value for an empty slice
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#issuecomment-2161706873
## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/546?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 33.98%. Comparing base [(`32c61f5`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/32c61f5902418f8288adf76cfb96cc58f1ad4201?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`8b8b9cd`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/8b8b9cdb18d45ab8950726a1fdeb32f138010fc5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 8 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #546 +/- ##
=============================================
- Coverage 54.78% 33.98% -20.81%
- Complexity 795 797 +2
=============================================
Files 103 106 +3
Lines 9690 38586 +28896
Branches 1844 8566 +6722
=============================================
+ Hits 5309 13113 +7804
- Misses 3427 22736 +19309
- Partials 954 2737 +1783
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/546?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Upgrade to Rust 1.78 and fix issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1632322840
##########
core/src/execution/sort.rs:
##########
@@ -159,12 +159,14 @@ where
pos += 1;
}
} else {
- unsafe {
- ptr::copy_nonoverlapping(
- bucket.as_ptr(),
- self.get_unchecked_mut(pos),
- bucket.len(),
- );
+ if bucket.len() > 0 {
Review Comment:
test were panicking trying to copy an empty slice
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#issuecomment-2168255105
@parthchandra @kazuyukitanimura @huaxingao @comphead @viirya This is ready for review now
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1638984957
##########
core/src/execution/sort.rs:
##########
@@ -159,12 +159,16 @@ where
pos += 1;
}
} else {
- unsafe {
- ptr::copy_nonoverlapping(
- bucket.as_ptr(),
- self.get_unchecked_mut(pos),
- bucket.len(),
- );
+ if !bucket.is_empty() {
Review Comment:
Without this check we were hitting a debug assertion on the call to `get_unchecked_mut(pos)`
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1638984525
##########
core/src/execution/datafusion/spark_hash.rs:
##########
@@ -85,11 +85,16 @@ pub(crate) fn spark_compatible_murmur3_hash<T: AsRef<[u8]>>(data: T, seed: u32)
// safety:
// avoid boundary checking in performance critical codes.
// all operations are guaranteed to be safe
+ // data is &[u8] so we do not need to check for proper alignment
unsafe {
- let mut h1 = hash_bytes_by_int(
- std::slice::from_raw_parts(data.get_unchecked(0), len_aligned),
- seed,
- );
+ let mut h1 = if len_aligned > 0 {
Review Comment:
Without this check we were hitting a debug assertion on the call to `get_unchecked(0)`
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1640135715
##########
core/src/execution/sort.rs:
##########
@@ -159,12 +159,16 @@ where
pos += 1;
}
} else {
- unsafe {
- ptr::copy_nonoverlapping(
- bucket.as_ptr(),
- self.get_unchecked_mut(pos),
- bucket.len(),
- );
+ if !bucket.is_empty() {
Review Comment:
nvm, if its empty, we should just skip it
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Upgrade to Rust 1.78 and fix issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1632321751
##########
core/src/parquet/util/hash_util.rs:
##########
@@ -45,17 +47,19 @@ const MURMUR_R: i32 = 47;
unsafe fn murmur_hash2_64a(data_bytes: &[u8], seed: u64) -> u64 {
let len = data_bytes.len();
let len_64 = (len / 8) * 8;
- let data_bytes_64 =
- std::slice::from_raw_parts(&data_bytes[0..len_64] as *const [u8] as *const u64, len / 8);
Review Comment:
This is unsafe because it does not create a u64-aligned buffer and results in a panic with Rust 1.78
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Upgrade to Rust 1.78 and fix UB issues in unsafe code [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #546:
URL: https://github.com/apache/datafusion-comet/pull/546#discussion_r1638984957
##########
core/src/execution/sort.rs:
##########
@@ -159,12 +159,16 @@ where
pos += 1;
}
} else {
- unsafe {
- ptr::copy_nonoverlapping(
- bucket.as_ptr(),
- self.get_unchecked_mut(pos),
- bucket.len(),
- );
+ if !bucket.is_empty() {
Review Comment:
Without this check we were hitting a debug assertion when trying to copy an empty slice
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org