[merge] knit index robustness/corruption?

Martin Pool mbp at sourcefrog.net
Wed Jun 27 05:44:05 BST 2007


On 6/27/07, Robert Collins <robertc at robertcollins.net> wrote:

> The patch is wrong : its stripping the parent from the record being
> processed, rather than skipping the record being processed. This will
> lead to incorrect parents on that record, rather than that record being
> absent.

Good catch.  How about this instead, so that at least if someone else
encounters it (which seems unlikely) we will have a bit more context
to work from.

=== modified file 'bzrlib/knit.py'
--- bzrlib/knit.py      2007-06-21 03:29:39 +0000
+++ bzrlib/knit.py      2007-06-27 04:42:27 +0000
@@ -1185,14 +1185,18 @@
                 # 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:
+                raise errors.KnitCorrupt(self._filename,
+                    "line %r: %s" % (rec, e))

             version_id, options, pos, size = rec[:4]
             version_id = version_id

-- 
Martin



More information about the bazaar mailing list