bastion-rs / bastion

Highly-available Distributed Fault-tolerant Runtime
https://www.bastion-rs.com
Apache License 2.0
2.79k stars 103 forks source link

Possible panic issue in set_for_current #345

Open kitcatier opened 1 year ago

kitcatier commented 1 year ago

Hello, I found a soundness issue in this crate. https://github.com/bastion-rs/bastion/blob/c6016a95f64965e0b9ae61c18fdfbe3437eef65f/src/bastion-executor/src/placement.rs#L20-L23 Here's a quick example of this issue:

extern crate bastion_executor;
use bastion_executor::placement::CoreId;

fn main() {
    let a:CoreId = CoreId { id: 771157545605903283 };
    let _ = bastion_executor::placement::set_for_current(a);
}

This outputs:

thread 'main' panicked at 'attempt to shift left with overflow', C:\Users\.cargo\registry\src\github.com-1ecc6299db9ec823\bastion-executor-0.4.2\src\placement.rs:216:31
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/73c9eaf21454b718e7c549984d9eb6e1f75e995c/library\std\src\panicking.rs:575
   1: core::panicking::panic_fmt
             at /rustc/73c9eaf21454b718e7c549984d9eb6e1f75e995c/library\core\src\panicking.rs:65
   2: core::panicking::panic
             at /rustc/73c9eaf21454b718e7c549984d9eb6e1f75e995c/library\core\src\panicking.rs:115
   3: bastion_executor::placement::windows::set_for_current
             at C:\Users\.cargo\registry\src\github.com-1ecc6299db9ec823\bastion-executor-0.4.2\src\placement.rs:216
   4: bastion_executor::placement::set_for_current_helper
             at C:\Users\.cargo\registry\src\github.com-1ecc6299db9ec823\bastion-executor-0.4.2\src\placement.rs:180
   5: bastion_executor::placement::set_for_current
             at C:\Users\.cargo\registry\src\github.com-1ecc6299db9ec823\bastion-executor-0.4.2\src\placement.rs:22
   6: hello::main
             at .\src\main.rs:14
   7: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/73c9eaf21454b718e7c549984d9eb6e1f75e995c\library\core\src\ops\function.rs:510
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.