You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I realize TreeFocus is an implementation detail and not really meant to be used by end-users of the library but I think this opens up the possibility of causing data-races through safe Rust code like this:
#![forbid(unsafe_code)]use im::vector;use im::vector::{Vector,Focus};use std::{iter, iter::FromIterator, cell::Cell};use crossbeam_utils::thread;#[derive(Debug,Clone,Copy)]enumRefOrInt<'a>{Ref(&'au64),Int(u64),}staticSOME_INT:u64 = 123;fnmain(){let cell = Cell::new(RefOrInt::Ref(&SOME_INT));// Make the Vector big enough so that it gets promoted to a RRB tree.letmut vec:Vector<&Cell<RefOrInt>> = Vector::from_iter(
iter::repeat(&cell).take(1024*5));let focus = vec.focus();ifletFocus::Full(tree_focus) = focus {
thread::scope(|s| {
s.spawn(move |_| {letmut sent_focus = tree_focus;let smuggled_cell = sent_focus.get(0).unwrap();loop{// Repeatedly write Ref(&addr) and Int(0xdeadbeef) into the cell.
smuggled_cell.set(RefOrInt::Ref(&SOME_INT));
smuggled_cell.set(RefOrInt::Int(0xdeadbeef));}});loop{ifletRefOrInt::Ref(addr) = cell.get(){// Hope that between the time we pattern match the object as a// `Ref`, it gets written to by the other thread.if addr as*constu64 == &SOME_INTas*constu64{continue;}// Due to the data race, obtaining Ref(0xdeadbeef) is possibleprintln!("Pointer is now: {:p}", addr);println!("Dereferencing addr will now segfault: {}",*addr);}}});}}
which outputs
Pointer is now: 0xdeadbeef
Return Code: -11 (SIGSEGV)
It looks like the version of
Focus
for RRB-tree backed vectors,TreeFocus
lacks bounds forSync
andSend
:im-rs/src/vector/focus.rs
Lines 280 to 285 in 22f6907
I realize
TreeFocus
is an implementation detail and not really meant to be used by end-users of the library but I think this opens up the possibility of causing data-races through safe Rust code like this:which outputs
(Issue found by the Rust group at @sslab-gatech)
The text was updated successfully, but these errors were encountered: