-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 soundness issue in make_contiguous
#79814
Conversation
r? @cramertj (rust-highfive has picked a reviewer for you, use r? to override) |
@@ -2839,7 +2839,7 @@ impl<T> From<VecDeque<T>> for Vec<T> { | |||
let len = other.len(); | |||
let cap = other.cap(); | |||
|
|||
if other.head != 0 { | |||
if other.tail != 0 { |
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.
this was only a perfomance issue because is_contiguous
returns false if the head
is 0
#[test] | ||
fn make_contiguous_head_to_end() { | ||
let mut dq = VecDeque::with_capacity(3); | ||
dq.push_front('B'); | ||
dq.push_front('A'); | ||
dq.push_back('C'); | ||
dq.make_contiguous(); | ||
let expected_tail = 0; | ||
let expected_head = 3; | ||
assert_eq!(expected_tail, dq.tail); | ||
assert_eq!(expected_head, dq.head); | ||
assert_eq!((&['A', 'B', 'C'] as &[_], &[] as &[_]), dq.as_slices()); | ||
} |
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.
Do you want to write a version of this that uses Box
es so that we ensure it doesn't segfault?
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.
that shouldn't matter i think. The reason this could segfault is if the result is wrong. But as the used algorithm doesn't depend on T
asserting that it is correct for i32
also means that it would be correct for Box
and therefore can't segfault.
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.
Probably, but I figured better safe than sorry :)
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.
yeah, don't have the capacity for this rn though.
This seems ok, I'd like to get it merged ASAP so we can get testing to the extent possible. @bors r+ p=1 I admit the code is pretty high-context I think in terms of being able to follow it. |
📌 Commit 4fb9f1d has been approved by |
(I removed |
☀️ Test successful - checks-actions |
…ulacrum [beta] backports * Revert rust-lang#77534 fixing rust-lang#77713 on beta, principled fix landed on master * fix soundness issue in `make_contiguous` rust-lang#79814 * Fix exhaustiveness in case a byte string literal is used at slice type rust-lang#79072
The process for stable and beta nominations is the same - until they happen, both nominated and stable should be left. Reading. |
Oops, didn't realize that! Sorry. |
fixes #79808