-
Notifications
You must be signed in to change notification settings - Fork 13k
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 unaligned loads in librustc_metadata #38352
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
fn bytes_to_words(b: &[u8]) -> &[u32] { | ||
unsafe { slice::from_raw_parts(b.as_ptr() as *const u32, b.len() / 4) } | ||
fn bytes_to_words(b: &[u8]) -> UnalignedIter<u32> { | ||
UnalignedIter::from_slice(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm.. no, sorry! It is from before that.
This was reported as a crash on sparc64. |
60fd4e4
to
e6dc830
Compare
@@ -95,8 +98,8 @@ impl<'tcx> LazySeq<Index> { | |||
} | |||
} | |||
|
|||
fn bytes_to_words(b: &[u8]) -> &[u32] { | |||
unsafe { slice::from_raw_parts(b.as_ptr() as *const u32, b.len() / 4) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should lint against this? Creating a slice or reference from a less aligned pointer?
Creating a `&[u32]` from a `&[u8]` was not valid; the data is not necessarily well aligned.
e6dc830
to
7bc1054
Compare
Hey presto, the diff is much shorter with a bit of help from @eddyb. |
@bors r+ |
📌 Commit 7bc1054 has been approved by |
Fix unaligned loads in librustc_metadata Creating a `&[u32]` from an `&[u8]` is not necessarily valid, and crashes on certain platforms if the data is not well aligned.
Creating a
&[u32]
from an&[u8]
is not necessarily valid, and crasheson certain platforms if the data is not well aligned.