[llvm] [CAS] Harden validate() against on-disk corruption (PR #190634)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 10:09:18 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CAS/MappedFileRegionArena.h llvm/lib/CAS/DatabaseFile.cpp llvm/lib/CAS/MappedFileRegionArena.cpp llvm/lib/CAS/OnDiskGraphDB.cpp llvm/lib/CAS/OnDiskTrieRawHashMap.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CAS/MappedFileRegionArena.cpp b/llvm/lib/CAS/MappedFileRegionArena.cpp
index 630d77a5c..2dae3f2d0 100644
--- a/llvm/lib/CAS/MappedFileRegionArena.cpp
+++ b/llvm/lib/CAS/MappedFileRegionArena.cpp
@@ -348,9 +348,10 @@ Error MappedFileRegionArena::initializeHeader(uint64_t HeaderOffset) {
   uint64_t ExistingValue = 0;
   if (!H->BumpPtr.compare_exchange_strong(ExistingValue, HeaderEndOffset))
     if (ExistingValue < HeaderEndOffset)
-      return createStringError(make_error_code(std::errc::protocol_error),
-                               "arena bump pointer is corrupt: 0x" +
-                                   utohexstr(ExistingValue, /*LowerCase=*/true));
+      return createStringError(
+          make_error_code(std::errc::protocol_error),
+          "arena bump pointer is corrupt: 0x" +
+              utohexstr(ExistingValue, /*LowerCase=*/true));
   if (Logger)
     Logger->logMappedFileRegionArenaCreate(Path, *FD, data(), capacity(),
                                            size());
diff --git a/llvm/lib/CAS/OnDiskGraphDB.cpp b/llvm/lib/CAS/OnDiskGraphDB.cpp
index c6d47e9c8..f7405ff6e 100644
--- a/llvm/lib/CAS/OnDiskGraphDB.cpp
+++ b/llvm/lib/CAS/OnDiskGraphDB.cpp
@@ -968,7 +968,8 @@ Error OnDiskGraphDB::validate(bool Deep, HashingFuncT Hasher) const {
         return formatError("data record offset is not aligned");
 
       // Validate the layout flags before getFromDataPool calls getTotalSize().
-      auto HeaderData = DataPool.get(D.Offset, sizeof(DataRecordHandle::Header));
+      auto HeaderData =
+          DataPool.get(D.Offset, sizeof(DataRecordHandle::Header));
       if (!HeaderData)
         return formatError(toString(HeaderData.takeError()));
       auto LF = DataRecordHandle::get(HeaderData->data()).getLayoutFlags();

``````````

</details>


https://github.com/llvm/llvm-project/pull/190634


More information about the llvm-commits mailing list