[PATCH] D144565: dwp check overflow

zhuna via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 08:08:43 PST 2023


zhuna8616 created this revision.
Herald added a project: All.
zhuna8616 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144565

Files:
  llvm/tools/llvm-dwp/llvm-dwp.cpp


Index: llvm/tools/llvm-dwp/llvm-dwp.cpp
===================================================================
--- llvm/tools/llvm-dwp/llvm-dwp.cpp
+++ llvm/tools/llvm-dwp/llvm-dwp.cpp
@@ -462,8 +462,17 @@
     auto Index = getContributionIndex(Kind);
     if (Kind != DW_SECT_EXT_TYPES) {
       CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
-      ContributionOffsets[Index] +=
-          (CurEntry.Contributions[Index].Length = Contents.size());
+      APInt Offset{32, ContributionOffsets[Index], false};
+      APInt NewLength{
+          32, CurEntry.Contributions[Index].Length = Contents.size(), false};
+      bool Overflow = false;
+      APInt NewOffset = Offset.uadd_ov(NewLength, Overflow);
+      if (Overflow) {
+        std::string SectionName = SectionPair->first().str();
+        return make_error<DWPError>(
+            std::string("Section size overflow in " + SectionName));
+      }
+      ContributionOffsets[Index] = NewOffset.getLimitedValue();
     }
 
     switch (Kind) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144565.499514.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230222/e5fa8118/attachment.bin>


More information about the llvm-commits mailing list