Rev 6268: (jelmer) Raise BadIndexKey rather than crashing if the key is unreasonably in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Nov 17 12:09:50 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6268 [merge]
revision-id: pqm at pqm.ubuntu.com-20111117120949-9f5ayowxv6avzu8p
parent: pqm at pqm.ubuntu.com-20111117101637-xyvsf9w3943gkx2e
parent: weyrick at mozek.us-20111116205910-1xbpqbimbw3fvfqw
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-11-17 12:09:49 +0000
message:
(jelmer) 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-11-14 04:46:48 +0000
+++ b/bzrlib/btree_index.py 2011-11-16 20:59:10 +0000
@@ -294,8 +294,10 @@
flag when writing out. This is used by the _spill_mem_keys_to_disk
functionality.
"""
+ new_leaf = False
if rows[-1].writer is None:
# opening a new leaf chunk;
+ new_leaf = True
for pos, internal_row in enumerate(rows[:-1]):
# flesh out any internal nodes that are needed to
# preserve the height of the tree
@@ -320,6 +322,11 @@
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. raising the error avoids infinite recursion
+ # searching for a suitably large page that will not be found.
+ if new_leaf:
+ 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-11-14 04:46:48 +0000
+++ b/bzrlib/tests/test_btree_index.py 2011-11-16 20:59:10 +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-16 17:04:48 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-11-17 12:09:49 +0000
@@ -529,6 +529,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