[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 <aam@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
81059a1b79
commit
e991ffd37b
+3
-1
@@ -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<const uint32_t*>(bytes)[i]);
|
||||
hash = CombineHashes(
|
||||
hash, LoadUnaligned(&(reinterpret_cast<const uint32_t*>(bytes)[i])));
|
||||
}
|
||||
for (intptr_t i = chunks * kInt32Size; i < len; i++) {
|
||||
hash = CombineHashes(hash, reinterpret_cast<const uint8_t*>(bytes)[i]);
|
||||
|
||||
Reference in New Issue
Block a user