-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 vec::IntoIter::drop on high-alignment ZST #106084
Conversation
The Miri subtree was changed cc @rust-lang/miri Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
self.ptr = self.end; | ||
// For th ZST case, it is crucial that we mutate `end` here, not `ptr`. | ||
// `ptr` must stay aligned, while `end` may be unaligned. | ||
self.end = self.ptr; |
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.
FWIW I don't think we have a test for this (with a ZST that needs alignment)
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.
Wouldn't it be better to add the tests to std instead of the miri testsuite then?
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.
I'm not sure how this test would be written in std in a way that would actually test the behavior except under miri.
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 by adding an unsafe precondition debug assert to drop_in_place?
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.
I would not be opposed to that, but I don't think it needs to be done in this PR.
// which is valid for ZSTs. | ||
self.ptr = self.ptr.wrapping_byte_add(step_size); | ||
// See `next` for why we sub `end` here. | ||
self.end = self.end.wrapping_byte_sub(step_size); |
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.
FWIW I don't think we have a test for this (with a ZST that needs alignment)
Subtle, nice catch. @bors r+ rollup |
fix vec::IntoIter::drop on high-alignment ZST This fixes a soundness bug: IntoIter would call `drop_in_place` on an insufficiently aligned pointer. So if a ZST with alignment greater 1 had drop glue, that would be called with an unaligned reference. Since rust-lang#103957, Miri checks alignment even if the type does not have drop glue, which is how this bug was found. r? `@thomcc`
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#105970 (docs/test: add UI test and long-form error docs for E0462) - rust-lang#105975 (rustc: Remove needless lifetimes) - rust-lang#106069 (rustdoc: use a more evocative name for CSS/JS `#titles`) - rust-lang#106084 (fix vec::IntoIter::drop on high-alignment ZST) - rust-lang#106091 (Use correct CSS pseudo-element selector) - rust-lang#106093 (rustdoc: remove no-op CSS from `.docblock-short`) - rust-lang#106102 (Fix `triagebot.toml`) Failed merges: - rust-lang#106028 (docs/test: add UI test and long-form error docs for `E0461`) r? `@ghost` `@rustbot` modify labels: rollup
There is a way to write a test without Miri: define a ZST with high alignment and give it an impl Drop that checks alignment.
|
add lib tests for vec::IntoIter alignment issues This adds non-Miri tests for the issue fixed in rust-lang#106084 r? `@thomcc`
fix vec::IntoIter::drop on high-alignment ZST This fixes a soundness bug: IntoIter would call `drop_in_place` on an insufficiently aligned pointer. So if a ZST with alignment greater 1 had drop glue, that would be called with an unaligned reference. Since rust-lang#103957, Miri checks alignment even if the type does not have drop glue, which is how this bug was found. r? ``@thomcc``
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#105970 (docs/test: add UI test and long-form error docs for E0462) - rust-lang#105975 (rustc: Remove needless lifetimes) - rust-lang#106069 (rustdoc: use a more evocative name for CSS/JS `#titles`) - rust-lang#106084 (fix vec::IntoIter::drop on high-alignment ZST) - rust-lang#106091 (Use correct CSS pseudo-element selector) - rust-lang#106093 (rustdoc: remove no-op CSS from `.docblock-short`) - rust-lang#106102 (Fix `triagebot.toml`) Failed merges: - rust-lang#106028 (docs/test: add UI test and long-form error docs for `E0461`) r? `@ghost` `@rustbot` modify labels: rollup
add lib tests for vec::IntoIter alignment issues This adds non-Miri tests for the issue fixed in rust-lang/rust#106084 r? `@thomcc`
This fixes a soundness bug: IntoIter would call
drop_in_place
on an insufficiently aligned pointer. So if a ZST with alignment greater 1 had drop glue, that would be called with an unaligned reference. Since #103957, Miri checks alignment even if the type does not have drop glue, which is how this bug was found.r? @thomcc