From a9cd19a5fe92dbf872cd77bc39a75fa4b3d1833a Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 12 Aug 2021 19:23:25 -0400 Subject: [PATCH] fs: avoid unaligned access when copying btrfs search headers The assignment operator will use member-wise assignment, which assumes the object's this pointer is aligned. That doesn't happen when the object in question is part of a btrfs search result, and aarch64 faults over it. Use memcpy instead, which has no alignment constraints. Signed-off-by: Zygo Blaxell --- lib/fs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fs.cc b/lib/fs.cc index 53a3f94..48a9c36 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -748,7 +748,7 @@ namespace crucible { BtrfsIoctlSearchHeader::set_data(const vector &v, size_t offset) { THROW_CHECK2(invalid_argument, offset, v.size(), offset + sizeof(btrfs_ioctl_search_header) <= v.size()); - *static_cast(this) = *reinterpret_cast(&v[offset]); + memcpy(static_cast(this), &v[offset], sizeof(btrfs_ioctl_search_header)); offset += sizeof(btrfs_ioctl_search_header); THROW_CHECK2(invalid_argument, offset + len, v.size(), offset + len <= v.size()); m_data = Spanner(&v[offset], &v[offset + len]);