-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
[Merged by Bors] - Fix unsoundnes in insert
remove
and despawn
#7805
Conversation
archetype_id: swapped_location.archetype_id, | ||
archetype_row: old_location.archetype_row, | ||
table_id: swapped_location.table_id, | ||
table_row: swapped_location.table_row, |
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.
archetype_id: swapped_location.archetype_id, | |
archetype_row: old_location.archetype_row, | |
table_id: swapped_location.table_id, | |
table_row: swapped_location.table_row, | |
archetype_row: old_location.archetype_row, | |
..swapped_location |
Alternatively, we should consider exposing a pub(crate) get_mut
from Entities
or just mutate swapped_location with the archetype row.
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 specifically chose to construct a whole new struct here so that if we change the fields we'll get a compile error rather than it continuing to compile
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 makes sense to me. Not sure if the compiler will optimize that down though. Probably worth investigating separately.
Not sure if this is worth leaving a comment so others don't try to make that change.
archetype_id: swapped_location.archetype_id, | ||
archetype_row: swapped_location.archetype_row, | ||
table_id: swapped_location.table_id, | ||
table_row: old_location.table_row, |
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.
archetype_id: swapped_location.archetype_id, | |
archetype_row: swapped_location.archetype_row, | |
table_id: swapped_location.table_id, | |
table_row: old_location.table_row, | |
table_row: old_location.table_row, | |
..swapped_location |
Alternatively just mutate the table_row on swapped_location.
Insertion has the same UB, I think. Overwrites table row. bevy/crates/bevy_ecs/src/bundle.rs Lines 556 to 559 in d1a1f90
bevy/crates/bevy_ecs/src/bundle.rs Lines 584 to 587 in d1a1f90
Does not update table row on bevy/crates/bevy_ecs/src/bundle.rs Lines 597 to 613 in d1a1f90
|
8207654
to
9e76c86
Compare
EntityMut::move_entity_from_remove
insert
remove
and despawn
d81cd26
to
8795aae
Compare
8795aae
to
884b4d4
Compare
bors r+ |
`EntityMut::move_entity_from_remove` had two soundness bugs: - When removing the entity from the archetype, the swapped entity had its table row updated to the same as the removed entity's - When removing the entity from the table, the swapped entity did not have its table row updated `BundleInsert::insert` had two/three soundness bugs - When moving an entity to a new archetype from an `insert`, the swapped entity had its table row set to a different entities - When moving an entity to a new table from an `insert`, the swapped entity did not have its table row updated See added tests for examples that trigger those bugs `EntityMut::despawn` had two soundness bugs - When despawning an entity, the swapped entity had its table row set to a different entities even if the table didnt change - When despawning an entity, the swapped entity did not have its table row updated
Pull request successfully merged into main. Build succeeded:
|
insert
remove
and despawn
insert
remove
and despawn
`EntityMut::move_entity_from_remove` had two soundness bugs: - When removing the entity from the archetype, the swapped entity had its table row updated to the same as the removed entity's - When removing the entity from the table, the swapped entity did not have its table row updated `BundleInsert::insert` had two/three soundness bugs - When moving an entity to a new archetype from an `insert`, the swapped entity had its table row set to a different entities - When moving an entity to a new table from an `insert`, the swapped entity did not have its table row updated See added tests for examples that trigger those bugs `EntityMut::despawn` had two soundness bugs - When despawning an entity, the swapped entity had its table row set to a different entities even if the table didnt change - When despawning an entity, the swapped entity did not have its table row updated
EntityMut::move_entity_from_remove
had two soundness bugs:BundleInsert::insert
had two/three soundness bugsinsert
, the swapped entity had its table row set to a different entitiesinsert
, the swapped entity did not have its table row updatedSee added tests for examples that trigger those bugs
EntityMut::despawn
had two soundness bugs