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

Alexander Yermolovich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 22 13:11:02 PDT 2022


ayermolo created this revision.
Herald added subscribers: hoy, modimo, wenlei, hiraditya.
Herald added a project: All.
ayermolo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130395

Files:
  llvm/lib/DWP/DWP.cpp


Index: llvm/lib/DWP/DWP.cpp
===================================================================
--- llvm/lib/DWP/DWP.cpp
+++ 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,10 @@
                                                              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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130395.446957.patch
Type: text/x-patch
Size: 861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220722/ab8c6bed/attachment.bin>


More information about the llvm-commits mailing list