Manishearth / elsa

Append-only collections for Rust where borrows to entries can outlive insertions
Apache License 2.0
228 stars 33 forks source link

Fix integer overflow -> undefined behavior in LockFreeFrozenVec capacity #47

Closed kevinmehall closed 1 year ago

kevinmehall commented 1 year ago

The following example currently overflows usize in the calculation of the allocation size, writes into an allocation that is actually zero bytes, and segfaults:

use elsa::sync::*;

fn main() {
    let v = LockFreeFrozenVec::<u64>::with_capacity(1<<(64 - 3));
    loop { v.push(1); }
}

This changes it to use Layout::array, which checks for overflow.

Manishearth commented 1 year ago

nice catch!

(I really should mark the lock free stuff as experimental)