krl / bunch Goto Github PK
View Code? Open in Web Editor NEWAppend-only, on-disk key-value index
License: GNU General Public License v3.0
Append-only, on-disk key-value index
License: GNU General Public License v3.0
Hello ๐ฆ ,
Currently in the Sync
impl for Bunch<T>
, there is no Sync
bound on T
.
With that, it's possible to write code that causes undefined behavior when Bunch
is used from multiple threads.
Line 36 in 2623f9a
Below is a small & contrived proof-of-concept, where a segmentation fault can occur due to data race.
Running the example code below in Debug mode results in a segmentation fault.
#![forbid(unsafe_code)]
use bunch::Bunch;
use std::cell::Cell;
use std::sync::Arc;
use std::thread;
// A simple tagged union used to demonstrate problems with data races in Cell.
#[derive(Debug, Clone, Copy)]
enum RefOrInt<'a> {
Ref(&'a u64),
Int(u64),
}
static X: u64 = 0;
fn main() {
let bunch = Bunch::new();
// This item is not `Sync`, but yet can be pushed to `Bunch`.
let item_not_sync = Cell::new(RefOrInt::Ref(&X));
bunch.push(item_not_sync);
let arc_0 = Arc::new(bunch);
let arc_1 = Arc::clone(&arc_0);
let _child = thread::spawn(move || {
let smuggled_cell = arc_1.get(0);
loop {
smuggled_cell.set(RefOrInt::Int(0xdeadbeef));
smuggled_cell.set(RefOrInt::Ref(&X))
}
});
loop {
if let RefOrInt::Ref(addr) = arc_0.get(0).get() {
if addr as *const _ as usize != 0xdeadbeef {
continue;
}
// Due to the data race, obtaining Ref(0xdeadbeef) is possible
println!("Pointer is now: {:p}", addr);
println!("Dereferencing addr will now segfault: {}", *addr);
}
}
}
I think this issue can be resolved by adding a T: Sync
bound to unsafe impl<T> Sync for Bunch<T> {}
.
(Issue found by @sslab-gatech's Rust group)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.