Rev 2556: Give a cleaner error when failing to decode knit index entry. in http://sourcefrog.net/bzr/knit-index-reader

Martin Pool mbp at sourcefrog.net
Wed Jun 27 08:38:10 BST 2007


At http://sourcefrog.net/bzr/knit-index-reader

------------------------------------------------------------
revno: 2556
revision-id: mbp at sourcefrog.net-20070627073753-rrxu5bbux3vi5yda
parent: pqm at pqm.ubuntu.com-20070627023032-h316n5k05g1nqqem
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: knit-index-reader
timestamp: Wed 2007-06-27 17:37:53 +1000
message:
  Give a cleaner error when failing to decode knit index entry.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-06-21 03:29:39 +0000
+++ b/bzrlib/knit.py	2007-06-27 07:37:53 +0000
@@ -1185,14 +1185,26 @@
                 # or a different failure, and raise. RBC 20060407
                 continue
 
-            parents = []
-            for value in rec[4:-1]:
-                if value[0] == '.':
-                    # uncompressed reference
-                    parent_id = value[1:]
-                else:
-                    parent_id = history[int(value)]
-                parents.append(parent_id)
+            try:
+                parents = []
+                for value in rec[4:-1]:
+                    if value[0] == '.':
+                        # uncompressed reference
+                        parent_id = value[1:]
+                    else:
+                        parent_id = history[int(value)]
+                    parents.append(parent_id)
+            except (IndexError, ValueError), e:
+                # The parent could not be decoded to get its parent row. This
+                # at a minimum will cause this row to have wrong parents, or
+                # even to apply a delta to the wrong base and decode
+                # incorrectly. its therefore not usable, and because we have
+                # encountered a situation where a new knit index had this
+                # corrupt we can't asssume that no other rows referring to the
+                # index of this record actually mean the subsequent uncorrupt
+                # one, so we error.
+                raise errors.KnitCorrupt(self._filename,
+                    "line %r: %s" % (rec, e))
 
             version_id, options, pos, size = rec[:4]
             version_id = version_id




More information about the bazaar-commits mailing list