2
0
Эх сурвалжийг харах

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 жил өмнө
parent
commit
7be0ad609d

+ 5 - 0
attic/archive.py

@@ -509,6 +509,11 @@ class ArchiveChecker:
         for chunk_id, _ in self.chunks.iteritems():
             cdata = self.repository.get(chunk_id)
             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:
                 archive = msgpack.unpackb(data)
             except:

+ 3 - 1
attic/testsuite/archiver.py

@@ -383,7 +383,9 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
         repository.delete(Manifest.MANIFEST_ID)
         repository.commit()
         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)
 
     def test_extra_chunks(self):