[llvm] f8df811 - [DWP][DWARF] Detect and error on debug info offset overflow

Alexander Yermolovich via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 08:20:00 PDT 2022


Author: Alexander Yermolovich
Date: 2022-07-26T08:18:59-07:00
New Revision: f8df8114715bb18272e36d15b664b930dc79112f

URL: https://github.com/llvm/llvm-project/commit/f8df8114715bb18272e36d15b664b930dc79112f
DIFF: https://github.com/llvm/llvm-project/commit/f8df8114715bb18272e36d15b664b930dc79112f.diff

LOG: [DWP][DWARF] Detect and error on debug info offset overflow

Right now we silently overflow uint32_t for debug_indfo sections. Added a check
and error out.

Differential Revision: https://reviews.llvm.org/D130395

Added: 
    

Modified: 
    llvm/lib/DWP/DWP.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DWP/DWP.cpp b/llvm/lib/DWP/DWP.cpp
index 44e39c019e0ca..346f4dfd290d1 100644
--- a/llvm/lib/DWP/DWP.cpp
+++ b/llvm/lib/DWP/DWP.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Object/Decompressor.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include <limits>
 
 using namespace llvm;
 using namespace llvm::object;
@@ -654,6 +655,12 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
                                                              IndexVersion)];
           C.Offset = InfoSectionOffset;
           C.Length = Header.Length + 4;
+
+          if (std::numeric_limits<uint32_t>::max() - InfoSectionOffset <
+              C.Length)
+            return make_error<DWPError>(
+                "debug information section offset is greater than 4GB");
+
           UnitOffset += C.Length;
           if (Header.Version < 5 ||
               Header.UnitType == dwarf::DW_UT_split_compile) {


        


More information about the llvm-commits mailing list