Преглед изворни кода

repository: Fixed a potential infinite loop in recover_segment

Jonas Borgström пре 11 година
родитељ
комит
c1e1d6e9dd
1 измењених фајлова са 9 додато и 1 уклоњено
  1. 9 1
      attic/repository.py

+ 9 - 1
attic/repository.py

@@ -258,6 +258,8 @@ class Repository(object):
             current_index = None
             current_index = None
         if transaction_id is None:
         if transaction_id is None:
             transaction_id = self.get_index_transaction_id()
             transaction_id = self.get_index_transaction_id()
+        if transaction_id is None:
+            transaction_id = self.io.get_latest_segment()
         segments_transaction_id = self.io.get_segments_transaction_id()
         segments_transaction_id = self.io.get_segments_transaction_id()
         self.get_index(None)
         self.get_index(None)
         for segment, filename in self.io.segment_iterator():
         for segment, filename in self.io.segment_iterator():
@@ -417,6 +419,12 @@ class LoggedIO(object):
             for filename in filenames:
             for filename in filenames:
                 yield int(filename), os.path.join(dirpath, filename)
                 yield int(filename), os.path.join(dirpath, filename)
 
 
+
+    def get_latest_segment(self):
+        for segment, filename in self.segment_iterator(reverse=True):
+            return segment
+        return None
+
     def get_segments_transaction_id(self):
     def get_segments_transaction_id(self):
         """Verify that the transaction id is consistent with the index transaction id
         """Verify that the transaction id is consistent with the index transaction id
         """
         """
@@ -518,7 +526,7 @@ class LoggedIO(object):
             fd.write(MAGIC)
             fd.write(MAGIC)
             while len(data) >= self.header_fmt.size:
             while len(data) >= self.header_fmt.size:
                 crc, size, tag = self.header_fmt.unpack(data[:self.header_fmt.size])
                 crc, size, tag = self.header_fmt.unpack(data[:self.header_fmt.size])
-                if size > len(data):
+                if size < self.header_fmt.size or size > len(data):
                     data = data[1:]
                     data = data[1:]
                     continue
                     continue
                 if crc32(data[4:size]) & 0xffffffff != crc:
                 if crc32(data[4:size]) & 0xffffffff != crc: