Bläddra i källkod

Make the manifest rebuild code more robust

Try to make sure we've actually found msgpack data before feeding
it into msgpack.
Jonas Borgström 11 år sedan
förälder
incheckning
7be0ad609d
2 ändrade filer med 8 tillägg och 1 borttagningar
  1. 5 0
      attic/archive.py
  2. 3 1
      attic/testsuite/archiver.py

+ 5 - 0
attic/archive.py

@@ -509,6 +509,11 @@ class ArchiveChecker:
         for chunk_id, _ in self.chunks.iteritems():
         for chunk_id, _ in self.chunks.iteritems():
             cdata = self.repository.get(chunk_id)
             cdata = self.repository.get(chunk_id)
             data = self.key.decrypt(chunk_id, cdata)
             data = self.key.decrypt(chunk_id, cdata)
+            # Some basic sanity checks of the payload before feeding it into msgpack
+            if len(data) < 2 or ((data[0] & 0xf0) != 0x80) or ((data[1] & 0xe0) != 0xa0):
+                continue
+            if not b'cmdline' in data or not b'\xa7version\x01' in data:
+                continue
             try:
             try:
                 archive = msgpack.unpackb(data)
                 archive = msgpack.unpackb(data)
             except:
             except:

+ 3 - 1
attic/testsuite/archiver.py

@@ -383,7 +383,9 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
         repository.delete(Manifest.MANIFEST_ID)
         repository.delete(Manifest.MANIFEST_ID)
         repository.commit()
         repository.commit()
         self.attic('check', self.repository_location, exit_code=1)
         self.attic('check', self.repository_location, exit_code=1)
-        self.attic('check', '--repair', self.repository_location, exit_code=0)
+        output = self.attic('check', '--repair', self.repository_location, exit_code=0)
+        self.assert_in('archive1', output)
+        self.assert_in('archive2', output)
         self.attic('check', self.repository_location, exit_code=0)
         self.attic('check', self.repository_location, exit_code=0)
 
 
     def test_extra_chunks(self):
     def test_extra_chunks(self):