Skip to content

Commit

Permalink
Force memcpy when reading a float, to avoid alignment issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piman@chromium.org committed Nov 18, 2013
1 parent 955f741 commit 522fbea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base/pickle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>();
if (!read_from)
return false;
memcpy(result, read_from, sizeof(*result));
return true;
}

bool PickleIterator::ReadString(std::string* result) {
Expand Down

0 comments on commit 522fbea

Please sign in to comment.