outbrain / fwumious_wabbit

Fwumious Wabbit, fast on-line machine learning toolkit written in Rust
Other
133 stars 19 forks source link

Add an alignment check before calling slice::from_raw_parts #27

Closed scottmcm closed 3 years ago

scottmcm commented 3 years ago

A Vec<u8>'s buffer is only guaranteed to be 1-aligned, but it's used here in code assuming it's 4-aligned. That might work, depending on what the allocator does, but it should be checked to avoid UB.

(Alternatively it could over-allocate the buffer and do something like align_to, but I didn't want to make broad changes.)

andraztori commented 3 years ago

Thank you! Yes, aligning is definitely an assumption that seems reasonable now, but could become invalid in the future! Also doing it perfectly properly with align_to would also be welcomed.

andraztori commented 3 years ago

@scottmcm Also thank you for the first external pull request!

scottmcm commented 3 years ago

You're welcome! I saw this in TWiR and got curious how it worked. Just happened to spot this in passing.