PR ld/10515
[binutils-gdb.git] / gold / dwarf_reader.cc
index ec697e428efde3f2c342d88c6ceb8a125e1cbae6..3d0f65a4b5a1cfb4ad6469b3ba3116e63fba431c 100644 (file)
@@ -32,7 +32,7 @@
 #include "reloc.h"
 #include "dwarf_reader.h"
 
-namespace {
+namespace gold {
 
 // Read an unsigned LEB128 number.  Each byte contains 7 bits of
 // information, plus one bit saying whether the number continues or
@@ -48,6 +48,12 @@ read_unsigned_LEB_128(const unsigned char* buffer, size_t* len)
 
   do
     {
+      if (num_read >= 64 / 7) 
+        {
+          gold_warning(_("Unusually large LEB128 decoded, "
+                        "debug information may be corrupted"));
+          break;
+        }
       byte = *buffer++;
       num_read++;
       result |= (static_cast<uint64_t>(byte & 0x7f)) << shift;
@@ -73,6 +79,12 @@ read_signed_LEB_128(const unsigned char* buffer, size_t* len)
 
   do
     {
+      if (num_read >= 64 / 7) 
+        {
+          gold_warning(_("Unusually large LEB128 decoded, "
+                        "debug information may be corrupted"));
+          break;
+        }
       byte = *buffer++;
       num_read++;
       result |= (static_cast<uint64_t>(byte & 0x7f) << shift);
@@ -86,11 +98,6 @@ read_signed_LEB_128(const unsigned char* buffer, size_t* len)
   return result;
 }
 
-} // End anonymous namespace.
-
-
-namespace gold {
-
 // This is the format of a DWARF2/3 line state machine that we process
 // opcodes using.  There is no need for anything outside the lineinfo
 // processor to know how this works.