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 unaligned loads in librustc_metadata #38352

Merged
merged 1 commit into from
Dec 16, 2016

Conversation

bluss
Copy link
Member

@bluss bluss commented Dec 13, 2016

Creating a &[u32] from an &[u8] is not necessarily valid, and crashes
on certain platforms if the data is not well aligned.

@rust-highfive
Copy link
Collaborator

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)
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @eddyb this was introduced in #36551

Copy link
Member Author

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.

@bluss
Copy link
Member Author

bluss commented Dec 13, 2016

This was reported as a crash on sparc64.

@@ -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) }
Copy link
Member Author

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.
@bluss
Copy link
Member Author

bluss commented Dec 14, 2016

Hey presto, the diff is much shorter with a bit of help from @eddyb.

@eddyb
Copy link
Member

eddyb commented Dec 14, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Dec 14, 2016

📌 Commit 7bc1054 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Dec 16, 2016

⌛ Testing commit 7bc1054 with merge 8ae9040...

bors added a commit that referenced this pull request Dec 16, 2016
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.
@bors bors merged commit 7bc1054 into rust-lang:master Dec 16, 2016
@bluss bluss deleted the unaligned-metadata branch December 16, 2016 19:23
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.

5 participants