Daniel-Liu-c0deb0t / triple_accel

Rust edit distance routines accelerated using SIMD. Supports fast Hamming, Levenshtein, restricted Damerau-Levenshtein, etc. distance calculations and string search.
MIT License
103 stars 13 forks source link

alloc_str is probably unsound #6

Open s3bk opened 3 years ago

s3bk commented 3 years ago

It allocates with a different alignment than it drops. It has to return a custom type that drops with the same layout as it allocates.

Daniel-Liu-c0deb0t commented 3 years ago

Yup, #4 is pretty much about the same thing. The fix would be to remove it, along with the hamming distance functions that rely on reading bytes as aligned integers. I believe that none of the main, re-exported functions actually use this (SIMD functions rely on unaligned reads), so it should be easily removable. An alternative is to use the ptr::read_unaligned function for safely reading unaligned bytes as integers.