-
-
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
Fix unsoundness in QueryState::is_empty
#9463
Conversation
Example |
Query::is_empty
safeQueryState::is_empty
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 is a solid fix! just one detail i have a query with.
I realized that the safety invariants were still a bit off (based on the incorrect assumption that |
# Objective `QueryState::is_empty` is unsound, as it does not validate the world. If a mismatched world is passed in, then the query filter may cast a component to an incorrect type, causing undefined behavior. ## Solution Add world validation. To prevent a performance regression in `Query` (whose world does not need to be validated), the unchecked function `is_empty_unsafe_world_cell` has been added. This also allows us to remove one of the last usages of the private function `UnsafeWorldCell::unsafe_world`, which takes us a step towards being able to remove that method entirely.
Objective
QueryState::is_empty
is unsound, as it does not validate the world. If a mismatched world is passed in, then the query filter may cast a component to an incorrect type, causing undefined behavior.Solution
Add world validation. To prevent a performance regression in
Query
(whose world does not need to be validated), the unchecked functionis_empty_unsafe_world_cell
has been added. This also allows us to remove one of the last usages of the private functionUnsafeWorldCell::unsafe_world
, which takes us a step towards being able to remove that method entirely.