shinmao opened a new issue, #4937:
URL: https://github.com/apache/arrow-rs/issues/4937

   ### The source of unsoundness
   Hi, we are the Rust researchers from 
[SunLab](https://sunlab-gmu.github.io/). Recently, we are trying to test our 
static analysis tool and find the potential unsound function in the package of 
`arrow-buffer`:
   
https://github.com/apache/arrow-rs/blob/90bc5ec96b5ae5162f469f9784dde7b1a53a5bdd/arrow-buffer/src/buffer/immutable.rs#L417-L432
   In line 429, when the mutable pointer is cast to generic type, it is 
actually casting from `u8` to any-aligned type which could create a misaligned 
pointer. However, it seems that the programmers are also aware of the bugs in 
the test case:
   
https://github.com/apache/arrow-rs/blob/90bc5ec96b5ae5162f469f9784dde7b1a53a5bdd/arrow-buffer/src/buffer/scalar.rs#L224-L231
   Here, `u8` is cast to `i32` and create a misaligned pointer and panic 
occurs.  
   We consider that it should not happen in safe API anyway based on the 
[safety requirement](https://doc.rust-lang.org/std/ptr/fn.write.html) of 
`ptr.write()`. The problem could be fixed by passing the layout of `element` to 
allocate the memory.
   We would love to have more discussion, and please correct if we are wrong.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to