fix: avoid unaligned pointer dereference (#12318)

This PR avoids undefined behavior in `String.Slice.hash` on unaligned
substrings.
This could produce a SIGILL on some Arm platforms.

Closes #12317
This commit is contained in:
Eric Wieser 2026-02-10 12:40:24 -08:00 committed by GitHub
parent c4d85b7622
commit c5d2796069
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <cstring>
#include "runtime/hash.h"
namespace lean {
@ -17,11 +18,13 @@ static uint64 MurmurHash64A(void const * key, size_t len, uint64 seed) {
uint64 h = seed ^ (len * m);
const uint64 * data = (const uint64 *)key;
const uint64 * end = data + (len/8);
const unsigned char * data = reinterpret_cast<const unsigned char *>(key);
const unsigned char * end = data + (len/8)*8;
while (data != end) {
uint64 k = *data++;
uint64 k;
memcpy(&k, data, 8);
data += 8;
k *= m;
k ^= k >> r;