Rev 6256: (mbp) raise BadIndexKey rather than crashing if the key is unreasonably long in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Fri Nov 11 04:36:35 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6256 [merge]
revision-id: pqm at pqm.ubuntu.com-20111111043634-m06vxk8sydn49od9
parent: pqm at pqm.ubuntu.com-20111110165231-0xhffujx5pgj4ssb
parent: weyrick at mozek.us-20111111010715-63ek15n527o73unp
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-11-11 04:36:34 +0000
message:
  (mbp) raise BadIndexKey rather than crashing if the key is unreasonably long
   (Shannon Weyrick)
modified:
  bzrlib/btree_index.py          index.py-20080624222253-p0x5f92uyh5hw734-7
  bzrlib/tests/test_btree_index.py test_index.py-20080624222253-p0x5f92uyh5hw734-13
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/btree_index.py'
--- a/bzrlib/btree_index.py	2011-08-19 22:34:02 +0000
+++ b/bzrlib/btree_index.py	2011-11-07 20:31:11 +0000
@@ -320,6 +320,12 @@
                 optimize_for_size=self._optimize_for_size)
             rows[-1].writer.write(_LEAF_FLAG)
         if rows[-1].writer.write(line):
+            # if we failed to write, despite having an empty page to write to,
+            # then line is too big. len is 2 here because we've already written
+            # some header. raising the error avoids infinite recursion searching
+            # for a suitably large page that will not be found.
+            if rows[-1].writer.bytes_out_len <= 2:
+                raise errors.BadIndexKey(string_key)
             # this key did not fit in the node:
             rows[-1].finish_node()
             key_line = string_key + "\n"

=== modified file 'bzrlib/tests/test_btree_index.py'
--- a/bzrlib/tests/test_btree_index.py	2011-08-19 22:34:02 +0000
+++ b/bzrlib/tests/test_btree_index.py	2011-11-08 18:52:34 +0000
@@ -831,6 +831,14 @@
             btree_index.BTreeGraphIndex(t1, 'index', 10) !=
             btree_index.BTreeGraphIndex(t1, 'index', 20))
 
+    def test_key_too_big(self):
+        # the size that matters here is the _compressed_ size of the key, so we can't
+        # do a simple character repeat.
+        bigKey = ''.join(map(repr, xrange(btree_index._PAGE_SIZE)))
+        self.assertRaises(errors.BadIndexKey,
+                          self.make_index,
+                          nodes=[((bigKey,), 'value', ())])
+        
     def test_iter_all_only_root_no_size(self):
         self.make_index(nodes=[(('key',), 'value', ())])
         t = transport.get_transport_from_url('trace+' + self.get_url(''))

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-10 13:56:18 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-11 01:07:15 +0000
@@ -511,6 +511,9 @@
   operations that use it, like merge, can now create trees without a root.
   (Aaron Bentley)
 
+* Raise BadIndexKey exception in btree_index when a key is too large, fixing 
+  an infinite recursion issue. (Shannon Weyrick, #720853)
+
 Documentation
 *************
 




More information about the bazaar-commits mailing list