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
Chunk API does not respect the align requirement of types. Unaligned reference can be created with the API, which is an undefined behavior.
Demonstration
Crate: chunky
Version: 0.3.7
OS: Ubuntu 18.04.5 LTS
Rust: rustc 1.47.0-nightly (bf4342114 2020-08-25)
#![forbid(unsafe_code)]use chunky::{HeapStorage,Ident,Value};use std::rc::Rc;#[repr(align(256))]structLargeAlign(u8);implDropforLargeAlign{fndrop(&mutself){println!("Dropped");}}fnmain(){let ident = Ident(String::from("ident"));let storage = Rc::new(HeapStorage);let value = Value::load_or_default(ident,LargeAlign(0), storage.clone());// Value reference does not have a correct alignmentlet v = &*value as*const_asusize;println!("{:x}", v);assert!(v% std::mem::align_of::<LargeAlign>()==0);// https://github.com/aeplay/chunky/blob/ef8533aec961eb5f415414dcd81ec4b395bae177/src/value.rs#L43-L49// Another bug that is not UB: `LargeAlign::Drop` is not called due to incorrect `drop_in_place()` in `Value::drop()`.// "Dropped" should be printed otherwise.}
Output:
555e921bea80
thread 'main' panicked at 'assertion failed: v % std::mem::align_of::<LargeAlign>() == 0', src/main.rs:42:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Return Code: 101
The text was updated successfully, but these errors were encountered:
chunky/src/value.rs
Lines 29 to 41 in ef8533a
Description
Chunk API does not respect the align requirement of types. Unaligned reference can be created with the API, which is an undefined behavior.
Demonstration
Output:
Return Code: 101
The text was updated successfully, but these errors were encountered: