[Merged by Bors] - Fix query.to_readonly().get_component_mut() soundness bug#6401
Closed
cart wants to merge 2 commits intobevyengine:mainfrom
Closed
[Merged by Bors] - Fix query.to_readonly().get_component_mut() soundness bug#6401cart wants to merge 2 commits intobevyengine:mainfrom
cart wants to merge 2 commits intobevyengine:mainfrom
Conversation
alice-i-cecile
approved these changes
Oct 29, 2022
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
Yeah okay it's hacky but fixes the problem without losing this very nice tool.
BoxyUwU
approved these changes
Oct 29, 2022
james7132
approved these changes
Oct 29, 2022
Member
james7132
left a comment
There was a problem hiding this comment.
I'm in agreement with Alice that this is pretty hacky, but it works.
Member
Author
|
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Oct 29, 2022
# Objective Fix the soundness issue outlined in #5866. In short the problem is that `query.to_readonly().get_component_mut::<T>()` can provide unsound mutable access to the component. This PR is an alternative to just removing the offending api. Given that `to_readonly` is a useful tool, I think this approach is a preferable short term solution. Long term I think theres a better solution out there, but we can find that on its own time. ## Solution Add what amounts to a "dirty flag" that marks Queries that have been converted to their read-only variant via `to_readonly` as dirty. When this flag is set to true, `get_component_mut` will fail with an error, preventing the unsound access.
Contributor
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Feb 1, 2023
…#6401) # Objective Fix the soundness issue outlined in bevyengine#5866. In short the problem is that `query.to_readonly().get_component_mut::<T>()` can provide unsound mutable access to the component. This PR is an alternative to just removing the offending api. Given that `to_readonly` is a useful tool, I think this approach is a preferable short term solution. Long term I think theres a better solution out there, but we can find that on its own time. ## Solution Add what amounts to a "dirty flag" that marks Queries that have been converted to their read-only variant via `to_readonly` as dirty. When this flag is set to true, `get_component_mut` will fail with an error, preventing the unsound access.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Objective
Fix the soundness issue outlined in #5866. In short the problem is that
query.to_readonly().get_component_mut::<T>()can provide unsound mutable access to the component. This PR is an alternative to just removing the offending api. Given thatto_readonlyis a useful tool, I think this approach is a preferable short term solution. Long term I think theres a better solution out there, but we can find that on its own time.Solution
Add what amounts to a "dirty flag" that marks Queries that have been converted to their read-only variant via
to_readonlyas dirty. When this flag is set to true,get_component_mutwill fail with an error, preventing the unsound access.