legion icon indicating copy to clipboard operation
legion copied to clipboard

Unsoundness in ResourceSet

Open TethysSvensson opened this issue 6 years ago • 2 comments

This program results in undefined behavior:

use legion::prelude::*;

fn fetcher() -> legion::resource::PreparedRead<u32> {
    let mut resources = Resources::default();
    resources.insert(0u32);

    <Read<u32>>::fetch(&resources)
}

fn main() {
    println!("0x{:x}", *fetcher());
}

TethysSvensson avatar Jan 12 '20 00:01 TethysSvensson

@jaynus would have to correct me but I think the Prepared* APIs were intended for use inside of System scheduler implementations? PreparedRead has a Safety section, but the ResourceSet impl just returns it without regard to those.

kabergstrom avatar Jan 12 '20 23:01 kabergstrom

Your correct, it intentionally erases lifetimes for the system usage. I'll need to add another layer of time indirection into the system implementation to erase in a differnt location so it's not exposed to the user.

jaynus avatar Jan 13 '20 00:01 jaynus