Commit 2dc1d07
authored
Fix
## Objective
Fixes #22842. TLDR: `AnimationTargetId::from_iter` wrongly returns the
same id for `["ab"]` and `["a", "b"]`.
## Solution
As suggested in the issue, add the length of each string to the hash.
The original suggestion used `to_be_bytes`, but I used `to_le_bytes` on
the assumption that most users are targeting LE and this will be more
efficient.
- There's probably a way to break it with maliciously crafted names, but
I can't imagine a case where that's a problem.
- I considered hashing `0xffu8` after each string instead of the length.
- That would be more efficient, and should be safe since it's not a
valid UTF8 character.
- But I wasn't quite confident enough.
- I also refactored `AnimationTargetId::from_names` to reuse
`AnimationTargetId::from_iter`.
## Testing
```sh
cargo test -p bevy_animation
cargo run --example animated_mesh
cargo run --example animated_mesh_events
cargo run --example animation_masks
```AnimationTargetId collisions (#22876)1 parent dd6eb2a commit 2dc1d07
File tree
2 files changed
+58
-7
lines changed- crates/bevy_animation/src
- release-content/migration-guides
2 files changed
+58
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1263 | 1263 | | |
1264 | 1264 | | |
1265 | 1265 | | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
| 1266 | + | |
1273 | 1267 | | |
1274 | 1268 | | |
1275 | 1269 | | |
| |||
1287 | 1281 | | |
1288 | 1282 | | |
1289 | 1283 | | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1290 | 1287 | | |
1291 | 1288 | | |
1292 | 1289 | | |
| |||
1664 | 1661 | | |
1665 | 1662 | | |
1666 | 1663 | | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
1667 | 1707 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments