Merge lp:~weyrick/bzr/720853-max-recursion-depth into lp:bzr

Proposed by Shannon Weyrick
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 6268
Proposed branch: lp:~weyrick/bzr/720853-max-recursion-depth
Merge into: lp:bzr
Diff against target: 58 lines (+18/-0)
3 files modified
bzrlib/btree_index.py (+7/-0)
bzrlib/tests/test_btree_index.py (+8/-0)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~weyrick/bzr/720853-max-recursion-depth
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+82453@code.launchpad.net

Commit message

Raise BadIndexKey rather than crashing if the key is unreasonably long.

Description of the change

Version 2 of this patch, which fixes the recursion issue in a way that doesn't break the pack command

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/16/2011 10:09 PM, Shannon Weyrick wrote:
> Shannon Weyrick has proposed merging
> lp:~weyrick/bzr/720853-max-recursion-depth into lp:bzr.
>
> Requested reviews: bzr-core (bzr-core) Related bugs: Bug #720853 in
> Bazaar: "bzr crashed with RuntimeError in normpath(): maximum
> recursion depth exceeded while calling a Python object"
> https://bugs.launchpad.net/bzr/+bug/720853 Bug #889872 in Bazaar:
> "not a valid key error" https://bugs.launchpad.net/bzr/+bug/889872
>
> For more details, see:
> https://code.launchpad.net/~weyrick/bzr/720853-max-recursion-depth/+merge/82453
>
> Version 2 of this patch, which fixes the recursion issue in a way
> that doesn't break the pack command

 merge: approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7E3pAACgkQJdeBCYSNAANS6wCg11uEStRmQaGk38pF45DgkuOh
Ef4AoJh16ykm7zk+kIa7PPwiRSlY4yZu
=l+zk
-----END PGP SIGNATURE-----

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/btree_index.py'
2--- bzrlib/btree_index.py 2011-11-14 04:46:48 +0000
3+++ bzrlib/btree_index.py 2011-11-16 21:07:26 +0000
4@@ -294,8 +294,10 @@
5 flag when writing out. This is used by the _spill_mem_keys_to_disk
6 functionality.
7 """
8+ new_leaf = False
9 if rows[-1].writer is None:
10 # opening a new leaf chunk;
11+ new_leaf = True
12 for pos, internal_row in enumerate(rows[:-1]):
13 # flesh out any internal nodes that are needed to
14 # preserve the height of the tree
15@@ -320,6 +322,11 @@
16 optimize_for_size=self._optimize_for_size)
17 rows[-1].writer.write(_LEAF_FLAG)
18 if rows[-1].writer.write(line):
19+ # if we failed to write, despite having an empty page to write to,
20+ # then line is too big. raising the error avoids infinite recursion
21+ # searching for a suitably large page that will not be found.
22+ if new_leaf:
23+ raise errors.BadIndexKey(string_key)
24 # this key did not fit in the node:
25 rows[-1].finish_node()
26 key_line = string_key + "\n"
27
28=== modified file 'bzrlib/tests/test_btree_index.py'
29--- bzrlib/tests/test_btree_index.py 2011-11-14 04:46:48 +0000
30+++ bzrlib/tests/test_btree_index.py 2011-11-16 21:07:26 +0000
31@@ -831,6 +831,14 @@
32 btree_index.BTreeGraphIndex(t1, 'index', 10) !=
33 btree_index.BTreeGraphIndex(t1, 'index', 20))
34
35+ def test_key_too_big(self):
36+ # the size that matters here is the _compressed_ size of the key, so we can't
37+ # do a simple character repeat.
38+ bigKey = ''.join(map(repr, xrange(btree_index._PAGE_SIZE)))
39+ self.assertRaises(errors.BadIndexKey,
40+ self.make_index,
41+ nodes=[((bigKey,), 'value', ())])
42+
43 def test_iter_all_only_root_no_size(self):
44 self.make_index(nodes=[(('key',), 'value', ())])
45 t = transport.get_transport_from_url('trace+' + self.get_url(''))
46
47=== modified file 'doc/en/release-notes/bzr-2.5.txt'
48--- doc/en/release-notes/bzr-2.5.txt 2011-11-16 17:04:48 +0000
49+++ doc/en/release-notes/bzr-2.5.txt 2011-11-16 21:07:26 +0000
50@@ -529,6 +529,9 @@
51 operations that use it, like merge, can now create trees without a root.
52 (Aaron Bentley)
53
54+* Raise BadIndexKey exception in btree_index when a key is too large, fixing
55+ an infinite recursion issue. (Shannon Weyrick, #720853)
56+
57 Documentation
58 *************
59