Rev 2497: Add a test that KnitCorrupt is raised when parent strings are invalid. in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/knit_index_pyrex

John Arbash Meinel john at arbash-meinel.com
Fri Jun 29 01:31:34 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/knit_index_pyrex

------------------------------------------------------------
revno: 2497
revision-id: john at arbash-meinel.com-20070629003100-xthewxf3hpdes9ix
parent: john at arbash-meinel.com-20070629001013-puyhbgbq0pgzvezu
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: knit_index_pyrex
timestamp: Thu 2007-06-28 19:31:00 -0500
message:
  Add a test that KnitCorrupt is raised when parent strings are invalid.
  And fix *both* implementations so that they do the right thing.
modified:
  bzrlib/_knit_load_data_c.pyx   knit_c.pyx-20070509143944-u42gy8w387a10m0j-1
  bzrlib/_knit_load_data_py.py   _knit_load_data_py.p-20070629000948-9a0nh4s118bi5y8n-1
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
-------------- next part --------------
=== modified file 'bzrlib/_knit_load_data_c.pyx'
--- a/bzrlib/_knit_load_data_c.pyx	2007-06-29 00:10:13 +0000
+++ b/bzrlib/_knit_load_data_c.pyx	2007-06-29 00:31:00 +0000
@@ -126,7 +126,7 @@
             next_option = PyString_FromStringAndSize(option_str,
                                                      next - option_str)
             PyList_Append(final_options, next_option)
-                          
+
             # Move past the ','
             option_str = next+1
 
@@ -176,7 +176,7 @@
                     raise IndexError('Parent index refers to a revision which'
                         ' does not exist yet.'
                         ' %d > %d' % (int_parent, self.history_len))
-                if end < next-1:
+                if parent_end < next:
                     # We didn't process all of the string, which means it isn't
                     # a complete integer.
                     py_parent = PyString_FromStringAndSize(parent_str,
@@ -245,7 +245,7 @@
         except (ValueError, IndexError), e:
             py_line = PyString_FromStringAndSize(start, end - start)
             raise errors.KnitCorrupt(self.kndx._filename,
-                "line %r: %s" % (py_line, e))
+                                     "line %r: %s" % (py_line, e))
 
         cache_entry = PyDict_GetItem_void(self.cache, version_id)
         if cache_entry == NULL:

=== modified file 'bzrlib/_knit_load_data_py.py'
--- a/bzrlib/_knit_load_data_py.py	2007-06-29 00:10:13 +0000
+++ b/bzrlib/_knit_load_data_py.py	2007-06-29 00:31:00 +0000
@@ -60,8 +60,7 @@
             # 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))
+            raise errors.KnitCorrupt(kndx._filename, "line %r: %s" % (rec, e))
 
         version_id, options, pos, size = rec[:4]
         version_id = version_id

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2007-06-29 00:10:13 +0000
+++ b/bzrlib/tests/test_knit.py	2007-06-29 00:31:00 +0000
@@ -698,6 +698,36 @@
         self.assertRaises(RevisionNotPresent, check, ["c"])
         self.assertRaises(RevisionNotPresent, check, ["a", "b", "c"])
 
+    def test_impossible_parent(self):
+        """Test we get KnitCorrupt if the parent couldn't possibly exist."""
+        transport = MockTransport([
+            _KnitIndex.HEADER,
+            "a option 0 1 :",
+            "b option 0 1 4 :"  # We don't have a 4th record
+            ])
+        self.assertRaises(errors.KnitCorrupt,
+                          self.get_knit_index, transport, 'filename', 'r')
+
+    def test_corrupted_parent(self):
+        transport = MockTransport([
+            _KnitIndex.HEADER,
+            "a option 0 1 :",
+            "b option 0 1 :",
+            "c option 0 1 1v :", # Can't have a parent of '1v'
+            ])
+        self.assertRaises(errors.KnitCorrupt,
+                          self.get_knit_index, transport, 'filename', 'r')
+
+    def test_corrupted_parent_in_list(self):
+        transport = MockTransport([
+            _KnitIndex.HEADER,
+            "a option 0 1 :",
+            "b option 0 1 :",
+            "c option 0 1 2 v :", # Can't have a parent of 'v'
+            ])
+        self.assertRaises(errors.KnitCorrupt,
+                          self.get_knit_index, transport, 'filename', 'r')
+
 
 class LowLevelKnitIndexTests_c(LowLevelKnitIndexTests):
 



More information about the bazaar-commits mailing list