[llvm] dd56bec - [CAS] Fix alignment error from MappedFileRegionArena (#159128)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 11:36:55 PDT 2025
Author: Steven Wu
Date: 2025-09-16T11:36:52-07:00
New Revision: dd56becdbc31cce16973172f0a447207ddf67861
URL: https://github.com/llvm/llvm-project/commit/dd56becdbc31cce16973172f0a447207ddf67861
DIFF: https://github.com/llvm/llvm-project/commit/dd56becdbc31cce16973172f0a447207ddf67861.diff
LOG: [CAS] Fix alignment error from MappedFileRegionArena (#159128)
Fix a bug that when an alignment error can happen when reading a slice
of file from existing MappedFileRegionArena.
Added:
Modified:
llvm/lib/CAS/MappedFileRegionArena.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CAS/MappedFileRegionArena.cpp b/llvm/lib/CAS/MappedFileRegionArena.cpp
index 2deb87d7adecf..472843d78af6e 100644
--- a/llvm/lib/CAS/MappedFileRegionArena.cpp
+++ b/llvm/lib/CAS/MappedFileRegionArena.cpp
@@ -216,17 +216,18 @@ Expected<MappedFileRegionArena> MappedFileRegionArena::create(
if (!Size)
return Size.takeError();
- Header *H = reinterpret_cast<Header *>(HeaderContent.data());
- if (H->HeaderOffset != HeaderOffset)
+ Header H;
+ memcpy(&H, HeaderContent.data(), sizeof(H));
+ if (H.HeaderOffset != HeaderOffset)
return createStringError(
std::make_error_code(std::errc::invalid_argument),
"specified header offset (" + utostr(HeaderOffset) +
- ") does not match existing config (" + utostr(H->HeaderOffset) +
+ ") does not match existing config (" + utostr(H.HeaderOffset) +
")");
// If the capacity doesn't match, use the existing capacity instead.
- if (H->Capacity != Capacity)
- Capacity = H->Capacity;
+ if (H.Capacity != Capacity)
+ Capacity = H.Capacity;
}
// If the size is smaller than capacity, we need to resize the file.
More information about the llvm-commits
mailing list