FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.51k stars 341 forks source link

Handle<T>unconditionally implements Send/Sync #482

Closed kuzeyardabulut closed 11 months ago

kuzeyardabulut commented 11 months ago

Hi, I found a memory-safety/soundness issue in this crate while scanning Rust code for potential vulnerabilities. This PR contains a fix for the issue.

Issue Description

Handle<T> unconditionally implements Sync. This allows users to create data races on T: !Sync. Such data races can lead to undefined behavior. https://github.com/FyroxEngine/Fyrox/blob/7f914495a85f95f9dc244c829be3ed94b2c8c098/fyrox-core/src/pool.rs#L203-L204

This may not cause a direct data race. But making changes can be useful.

kuzeyardabulut commented 11 months ago

480

mrDIMAS commented 11 months ago

It is impossible to get data races in Handle struct, because its fields are just both u32 which both Send + Sync. This unsafe impl is needed just to implement Send + Sync for PhantomData<T>. Any objections?