From ecebbbf5a6092fc627ebc8e9cc7b782e6c929b18 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Sat, 19 Oct 2019 03:25:20 +0800 Subject: [PATCH] murmurhash32 ubsan fix. --- contrib/murmurhash/src/murmurhash2.cpp | 6 ++++-- contrib/murmurhash/src/murmurhash3.cpp | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/contrib/murmurhash/src/murmurhash2.cpp b/contrib/murmurhash/src/murmurhash2.cpp index 8a41ba02d98..7b659f50b4c 100644 --- a/contrib/murmurhash/src/murmurhash2.cpp +++ b/contrib/murmurhash/src/murmurhash2.cpp @@ -13,6 +13,7 @@ // machines. #include "murmurhash2.h" +#include // Platform-specific functions and macros // Microsoft Visual Studio @@ -48,7 +49,8 @@ uint32_t MurmurHash2(const void * key, int len, uint32_t seed) while (len >= 4) { - uint32_t k = *reinterpret_cast(data); + uint32_t k; + memcpy(&k, data, sizeof(k)); k *= m; k ^= k >> r; k *= m; @@ -418,4 +420,4 @@ uint32_t MurmurHashAligned2(const void * key, int len, uint32_t seed) return h; } -} \ No newline at end of file +} diff --git a/contrib/murmurhash/src/murmurhash3.cpp b/contrib/murmurhash/src/murmurhash3.cpp index 2831bf5c73b..d6062340d03 100644 --- a/contrib/murmurhash/src/murmurhash3.cpp +++ b/contrib/murmurhash/src/murmurhash3.cpp @@ -7,6 +7,7 @@ // non-native version will be less than optimal. #include "murmurhash3.h" +#include //----------------------------------------------------------------------------- // Platform-specific functions and macros @@ -53,7 +54,9 @@ inline uint64_t rotl64 ( uint64_t x, int8_t r ) FORCE_INLINE uint32_t getblock32 ( const uint32_t * p, int i ) { - return p[i]; + uint32_t res; + memcpy(&res, p + i, sizeof(res)); + return res; } FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, int i )