-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Improve soundness of CommandQueue
#4863
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d599e6b
Use Vec<MaybeUninit<u8>> instead of Vec<u8> in CommandQueue
SkiFire13 9a11fbf
Use ManuallyDrop instead of std::mem::forget to not use command after…
SkiFire13 558c852
Remove useless check for Vec::as_mut_ptr equals to null
SkiFire13 9cb3dc8
Add comment explaining why self.bytes.as_mut_ptr() is valid when only…
SkiFire13 a9fdd9d
Add miri test for MaybeUninit<u8> vs u8 in CommandQueue
SkiFire13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't believe that this is technically sound (in the sense that the
std
docs aren't clear enough on this case) and instead relying on implementation details ofVec
- the docs forVec
guarantee that:However, that makes no guarantee that the
ptr
returned fromas_mut_ptr
isn't null. That's documented to:If the vector doesn't have a
buffer
then the documentation's assumed preconditions are not met. Therefore, any (non-UB having) implementation is permitted. This means that the pointer is the necessarily the same as the one above which is null-pointer optimised, therefore this could be a null pointer with an adverserial std implementation within the current docs.That being said, I'm happy accepting this anyway - it's clear that
std
intends to give this guarantee, and the fix for this is not to defensively program around it, but to engage withalloc
to get these docs clarified.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.
Going by what the docs say I don't think we can program against them with
is_null
,as_mut_ptr
could also return a freed pointer, which according to https://doc.rust-lang.org/stable/std/ptr/index.html#safety are also not valid for zero-sized reads. I guess the correct way to do this would be checking if the capacity is 0 rather than if the pointer is null. Anyway, I opened a PR to changeVec::as_ptr
andVec::as_mut_ptr
's docs, so hopefully this get clarified in the stdlib.