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

Alexander Yermolovich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 15:15:23 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/D130046

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,8 @@
 #include "llvm/Object/Decompressor.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include <cstdint>
+#include <limits>
 
 using namespace llvm;
 using namespace llvm::object;
@@ -679,6 +681,9 @@
               continue;
           }
           Out.emitBytes(Info.substr(UnitOffset - C.Length, C.Length));
+          if (std::numeric_limits<uint32_t>::max() - InfoSectionOffset < C.Length)
+            return make_error<DWPError>("Debug Info offset greater then 4GB.");
+
           InfoSectionOffset += C.Length;
         }
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130046.445639.patch
Type: text/x-patch
Size: 737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220718/ba58196a/attachment.bin>


More information about the llvm-commits mailing list