From d3f2a925ed502d420e2cd521e908acf167280387 Mon Sep 17 00:00:00 2001 From: Ivica Bogosavljevic Date: Tue, 20 Feb 2018 16:47:46 +0100 Subject: [PATCH] MIPS: Fix unaligned memory access in hash calculation During hash calculation, an array type was reinterpreted from uint16_[] to uint32_t[]. Uint32 arrays have stricter alignment requirements and these causes failures of several tests from the debugger suite. TEST=debugger/debug/debug-eval-scope Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I463c7aeb56a1010ddfb0c34f8404f05b75e6c466 Reviewed-on: https://chromium-review.googlesource.com/926341 Commit-Queue: Ivica Bogosavljevic Reviewed-by: Dmitry Gozman Cr-Commit-Position: refs/heads/master@{#51398} --- src/inspector/DEPS | 1 + src/inspector/v8-debugger-script.cc | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/inspector/DEPS b/src/inspector/DEPS index 85b506a956..f396d64b99 100644 --- a/src/inspector/DEPS +++ b/src/inspector/DEPS @@ -7,6 +7,7 @@ include_rules = [ "+src/base/platform/platform.h", "+src/conversions.h", "+src/flags.h", + "+src/utils.h", "+src/unicode-cache.h", "+src/inspector", "+src/tracing", diff --git a/src/inspector/v8-debugger-script.cc b/src/inspector/v8-debugger-script.cc index f5d9f4f4f4..c596ee5053 100644 --- a/src/inspector/v8-debugger-script.cc +++ b/src/inspector/v8-debugger-script.cc @@ -7,6 +7,7 @@ #include "src/inspector/inspected-context.h" #include "src/inspector/string-util.h" #include "src/inspector/wasm-translation.h" +#include "src/utils.h" namespace v8_inspector { @@ -45,10 +46,11 @@ String16 calculateHash(const String16& str) { size_t sizeInBytes = sizeof(UChar) * str.length(); data = reinterpret_cast(str.characters16()); for (size_t i = 0; i < sizeInBytes / 4; ++i) { + uint32_t d = v8::internal::ReadUnalignedUInt32(data + i); #if V8_TARGET_LITTLE_ENDIAN - uint32_t v = data[i]; + uint32_t v = d; #else - uint32_t v = (data[i] << 16) | (data[i] >> 16); + uint32_t v = (d << 16) | (d >> 16); #endif uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; @@ -57,15 +59,16 @@ String16 calculateHash(const String16& str) { } if (sizeInBytes % 4) { uint32_t v = 0; + const uint8_t* data_8b = reinterpret_cast(data); for (size_t i = sizeInBytes - sizeInBytes % 4; i < sizeInBytes; ++i) { v <<= 8; #if V8_TARGET_LITTLE_ENDIAN - v |= reinterpret_cast(data)[i]; + v |= data_8b[i]; #else if (i % 2) { - v |= reinterpret_cast(data)[i - 1]; + v |= data_8b[i - 1]; } else { - v |= reinterpret_cast(data)[i + 1]; + v |= data_8b[i + 1]; } #endif }