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 aliasing in Clone by using a raw pointer #523

Merged
merged 1 commit into from Apr 6, 2022

Conversation

saethlin
Copy link
Contributor

@saethlin saethlin commented Jan 2, 2022

Fixes #522

I feel like it would be good to add a test case to make sure such a thing doesn't come back, but I'm not sure how to do that. There's no way to usefully test this situation without running the code under Miri, but this project doesn't fully work with Miri anyway, because Miri doesn't understand int to pointer casts.

Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared
allocation upon cloning it. If the underlying allocation were actually
shared, such as through a &[u8] from the Deref impl, creating either of
these types incorrectly asserted uniqueness of the allocation.

This fixes the example in tokio-rs#522, but Miri still does not pass on this
test suite with -Zmiri-tag-raw-pointers because Miri does not currently
understand int to pointer casts.
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Sorry, I missed this when it was posted. It looks good.

@Darksonn Darksonn merged commit 7244769 into tokio-rs:master Apr 6, 2022
lelongg pushed a commit to lelongg/bytes that referenced this pull request Jan 9, 2023
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared
allocation upon cloning it. If the underlying allocation were actually
shared, such as through a &[u8] from the Deref impl, creating either of
these types incorrectly asserted uniqueness of the allocation.

This fixes the example in tokio-rs#522, but Miri still does not pass on this
test suite with -Zmiri-tag-raw-pointers because Miri does not currently
understand int to pointer casts.
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.

Unsoundness due to construction of &mut [u8] and Box<[u8]> in Clone impl
2 participants