Skip to content

Conversation

@kjvalencik
Copy link
Member

Currently, types used as the backing storage of external ArrayBuffer do not need to be 'static! This makes it trivial to create a soundness hole (use after free), with only safe Rust.

pub fn soundness_hole(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
    let mut data = vec![0u8, 1, 2, 3];
    
    // Creating an external from `&mut [u8]` instead of `Vec<u8>` since there is a blanket impl
    // of `AsMut<T> for &mut T`
    let buf = JsArrayBuffer::external(&mut cx, data.as_mut_slice());

    // `buf` is still holding a reference to `data`!
    drop(data);

    Ok(buf)
}

Fixes #896

@kjvalencik
Copy link
Member Author

Closing this PR. I'm going to reverse the cherry pick order so that main gets the CHANGELOG.

@kjvalencik kjvalencik closed this May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsArrayBuffer::external soundness hole

2 participants