From e991ffd37bba5b06f79db4bdcc48a62ee3dacd14 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 27 May 2026 12:55:21 -0700 Subject: [PATCH] [vm] Fix HashBytes to work with unaligned inputs. TEST=ubsan Bug: https://github.com/dart-lang/sdk/issues/63452 Change-Id: I112b26c08b5ae186dc5264d99edbed9e6e60368d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506660 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/vm/hash.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/vm/hash.h b/runtime/vm/hash.h index ceae2b7180c..2762c5537a8 100644 --- a/runtime/vm/hash.h +++ b/runtime/vm/hash.h @@ -6,6 +6,7 @@ #define RUNTIME_VM_HASH_H_ #include "platform/globals.h" +#include "platform/unaligned.h" namespace dart { @@ -41,7 +42,8 @@ inline uint32_t HashBytes(const void* bytes, uint32_t hash = len; const intptr_t chunks = len / kInt32Size; for (intptr_t i = 0; i < chunks; i++) { - hash = CombineHashes(hash, reinterpret_cast(bytes)[i]); + hash = CombineHashes( + hash, LoadUnaligned(&(reinterpret_cast(bytes)[i]))); } for (intptr_t i = chunks * kInt32Size; i < len; i++) { hash = CombineHashes(hash, reinterpret_cast(bytes)[i]);