annoy icon indicating copy to clipboard operation
annoy copied to clipboard

UBSAN issue with Hamming due misalignment

Open jlmelville opened this issue 4 years ago • 1 comments

../inst/include/annoylib.h:662:18: runtime error: load of misaligned address 0x55d2429c5424 for type 'const long unsigned int', which requires 8 byte alignment

Actually this PR won't fix that issue, and I'm not sure how to even fix it. Some thoughts:

  • Make sure that the memory is always aligned to 8 byte offsets, possibly using something like http://man7.org/linux/man-pages/man3/posix_memalign.3.html
  • Rewrite the hamming code to use 4 byte ints instead of 8 byte ints
  • Change the few places where we access v[i] to not use an array dereference

None of these are entirely trivial

Originally posted by @erikbern in https://github.com/spotify/annoy/pull/455#issuecomment-590152737

jlmelville avatar Feb 24 '20 03:02 jlmelville

It should be trivial to fix, and every reasonable C++ library should be tested with ASan+MSan+TSan+UBSan+Fuzzing.

alexey-milovidov avatar Sep 06 '22 03:09 alexey-milovidov