From 522fbeaf970881e5293e8f75cf5534ffb5a20d42 Mon Sep 17 00:00:00 2001 From: "piman@chromium.org" Date: Mon, 18 Nov 2013 00:50:25 +0000 Subject: [PATCH] Force memcpy when reading a float, to avoid alignment issues Despite our best efforts to align data when writing, when reading the data may not be sufficiently aligned, causing some ARM platforms to SIGBUS when reading floats. Force a memcpy instead to sidestep the issue. BUG=315213 Review URL: https://codereview.chromium.org/73333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235590 0039d316-1c4b-4281-b951-d872f2087c98 --- base/pickle.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/base/pickle.cc b/base/pickle.cc index 70dfa0d507a828..796fbc38beeb34 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -91,7 +91,15 @@ bool PickleIterator::ReadUInt64(uint64* result) { } bool PickleIterator::ReadFloat(float* result) { - return ReadBuiltinType(result); + // crbug.com/315213 + // The source data may not be properly aligned, and unaligned float reads + // cause SIGBUS on some ARM platforms, so force using memcpy to copy the data + // into the result. + const char* read_from = GetReadPointerAndAdvance(); + if (!read_from) + return false; + memcpy(result, read_from, sizeof(*result)); + return true; } bool PickleIterator::ReadString(std::string* result) {