[llvm] [DWARFLibrary] Add bounds check to Contrib index (PR #76405)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 26 11:45:50 PST 2023


https://github.com/DavidKorczynski created https://github.com/llvm/llvm-project/pull/76405

Index should be within the range of Contrib before being used as an index.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30308

>From 18d546b42e90e36766b7c98b60b143cd8ae682f3 Mon Sep 17 00:00:00 2001
From: David Korczynski <david at adalogics.com>
Date: Tue, 26 Dec 2023 11:57:39 -0800
Subject: [PATCH] [DWARFLibrary] Add bounds check to Contrib index

Index should be within the range of Contrib before being used as an
index.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30308

Signed-off-by: David Korczynski <david at adalogics.com>
---
 llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
index a4487e2dc21be1..208e3ac2c55343 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
@@ -157,6 +157,9 @@ bool DWARFUnitIndex::parseImpl(DataExtractor IndexData) {
     auto Index = IndexData.getU32(&Offset);
     if (!Index)
       continue;
+    // Ensure Index is in valid range
+    if (Index > Header.NumColumns)
+      return false;
     Rows[i].Index = this;
     Rows[i].Contributions =
         std::make_unique<Entry::SectionContribution[]>(Header.NumColumns);



More information about the llvm-commits mailing list