##// END OF EJS Templates
parseindex: also forward keyword argument in a debug wrapper...
Boris Feld -
r35983:c839bbee default
parent child Browse files
Show More
@@ -1,185 +1,185 b''
1 revlog.parseindex must be able to parse the index file even if
1 revlog.parseindex must be able to parse the index file even if
2 an index entry is split between two 64k blocks. The ideal test
2 an index entry is split between two 64k blocks. The ideal test
3 would be to create an index file with inline data where
3 would be to create an index file with inline data where
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
4 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
5 the size of an index entry) and with an index entry starting right
5 the size of an index entry) and with an index entry starting right
6 before the 64k block boundary, and try to read it.
6 before the 64k block boundary, and try to read it.
7 We approximate that by reducing the read buffer to 1 byte.
7 We approximate that by reducing the read buffer to 1 byte.
8
8
9 $ hg init a
9 $ hg init a
10 $ cd a
10 $ cd a
11 $ echo abc > foo
11 $ echo abc > foo
12 $ hg add foo
12 $ hg add foo
13 $ hg commit -m 'add foo'
13 $ hg commit -m 'add foo'
14 $ echo >> foo
14 $ echo >> foo
15 $ hg commit -m 'change foo'
15 $ hg commit -m 'change foo'
16 $ hg log -r 0:
16 $ hg log -r 0:
17 changeset: 0:7c31755bf9b5
17 changeset: 0:7c31755bf9b5
18 user: test
18 user: test
19 date: Thu Jan 01 00:00:00 1970 +0000
19 date: Thu Jan 01 00:00:00 1970 +0000
20 summary: add foo
20 summary: add foo
21
21
22 changeset: 1:26333235a41c
22 changeset: 1:26333235a41c
23 tag: tip
23 tag: tip
24 user: test
24 user: test
25 date: Thu Jan 01 00:00:00 1970 +0000
25 date: Thu Jan 01 00:00:00 1970 +0000
26 summary: change foo
26 summary: change foo
27
27
28 $ cat >> test.py << EOF
28 $ cat >> test.py << EOF
29 > from mercurial import changelog, vfs
29 > from mercurial import changelog, vfs
30 > from mercurial.node import *
30 > from mercurial.node import *
31 >
31 >
32 > class singlebyteread(object):
32 > class singlebyteread(object):
33 > def __init__(self, real):
33 > def __init__(self, real):
34 > self.real = real
34 > self.real = real
35 >
35 >
36 > def read(self, size=-1):
36 > def read(self, size=-1):
37 > if size == 65536:
37 > if size == 65536:
38 > size = 1
38 > size = 1
39 > return self.real.read(size)
39 > return self.real.read(size)
40 >
40 >
41 > def __getattr__(self, key):
41 > def __getattr__(self, key):
42 > return getattr(self.real, key)
42 > return getattr(self.real, key)
43 >
43 >
44 > def opener(*args):
44 > def opener(*args):
45 > o = vfs.vfs(*args)
45 > o = vfs.vfs(*args)
46 > def wrapper(*a):
46 > def wrapper(*a, **kwargs):
47 > f = o(*a)
47 > f = o(*a, **kwargs)
48 > return singlebyteread(f)
48 > return singlebyteread(f)
49 > return wrapper
49 > return wrapper
50 >
50 >
51 > cl = changelog.changelog(opener('.hg/store'))
51 > cl = changelog.changelog(opener('.hg/store'))
52 > print len(cl), 'revisions:'
52 > print len(cl), 'revisions:'
53 > for r in cl:
53 > for r in cl:
54 > print short(cl.node(r))
54 > print short(cl.node(r))
55 > EOF
55 > EOF
56 $ $PYTHON test.py
56 $ $PYTHON test.py
57 2 revisions:
57 2 revisions:
58 7c31755bf9b5
58 7c31755bf9b5
59 26333235a41c
59 26333235a41c
60
60
61 $ cd ..
61 $ cd ..
62
62
63 #if no-pure
63 #if no-pure
64
64
65 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
65 Test SEGV caused by bad revision passed to reachableroots() (issue4775):
66
66
67 $ cd a
67 $ cd a
68
68
69 $ $PYTHON <<EOF
69 $ $PYTHON <<EOF
70 > from mercurial import changelog, vfs
70 > from mercurial import changelog, vfs
71 > cl = changelog.changelog(vfs.vfs('.hg/store'))
71 > cl = changelog.changelog(vfs.vfs('.hg/store'))
72 > print 'good heads:'
72 > print 'good heads:'
73 > for head in [0, len(cl) - 1, -1]:
73 > for head in [0, len(cl) - 1, -1]:
74 > print'%s: %r' % (head, cl.reachableroots(0, [head], [0]))
74 > print'%s: %r' % (head, cl.reachableroots(0, [head], [0]))
75 > print 'bad heads:'
75 > print 'bad heads:'
76 > for head in [len(cl), 10000, -2, -10000, None]:
76 > for head in [len(cl), 10000, -2, -10000, None]:
77 > print '%s:' % head,
77 > print '%s:' % head,
78 > try:
78 > try:
79 > cl.reachableroots(0, [head], [0])
79 > cl.reachableroots(0, [head], [0])
80 > print 'uncaught buffer overflow?'
80 > print 'uncaught buffer overflow?'
81 > except (IndexError, TypeError) as inst:
81 > except (IndexError, TypeError) as inst:
82 > print inst
82 > print inst
83 > print 'good roots:'
83 > print 'good roots:'
84 > for root in [0, len(cl) - 1, -1]:
84 > for root in [0, len(cl) - 1, -1]:
85 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
85 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
86 > print 'out-of-range roots are ignored:'
86 > print 'out-of-range roots are ignored:'
87 > for root in [len(cl), 10000, -2, -10000]:
87 > for root in [len(cl), 10000, -2, -10000]:
88 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
88 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
89 > print 'bad roots:'
89 > print 'bad roots:'
90 > for root in [None]:
90 > for root in [None]:
91 > print '%s:' % root,
91 > print '%s:' % root,
92 > try:
92 > try:
93 > cl.reachableroots(root, [len(cl) - 1], [root])
93 > cl.reachableroots(root, [len(cl) - 1], [root])
94 > print 'uncaught error?'
94 > print 'uncaught error?'
95 > except TypeError as inst:
95 > except TypeError as inst:
96 > print inst
96 > print inst
97 > EOF
97 > EOF
98 good heads:
98 good heads:
99 0: [0]
99 0: [0]
100 1: [0]
100 1: [0]
101 -1: []
101 -1: []
102 bad heads:
102 bad heads:
103 2: head out of range
103 2: head out of range
104 10000: head out of range
104 10000: head out of range
105 -2: head out of range
105 -2: head out of range
106 -10000: head out of range
106 -10000: head out of range
107 None: an integer is required
107 None: an integer is required
108 good roots:
108 good roots:
109 0: [0]
109 0: [0]
110 1: [1]
110 1: [1]
111 -1: [-1]
111 -1: [-1]
112 out-of-range roots are ignored:
112 out-of-range roots are ignored:
113 2: []
113 2: []
114 10000: []
114 10000: []
115 -2: []
115 -2: []
116 -10000: []
116 -10000: []
117 bad roots:
117 bad roots:
118 None: an integer is required
118 None: an integer is required
119
119
120 $ cd ..
120 $ cd ..
121
121
122 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
122 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
123
123
124 $ mkdir invalidparent
124 $ mkdir invalidparent
125 $ cd invalidparent
125 $ cd invalidparent
126
126
127 $ hg clone --pull -q --config phases.publish=False ../a limit
127 $ hg clone --pull -q --config phases.publish=False ../a limit
128 $ hg clone --pull -q --config phases.publish=False ../a segv
128 $ hg clone --pull -q --config phases.publish=False ../a segv
129 $ rm -R limit/.hg/cache segv/.hg/cache
129 $ rm -R limit/.hg/cache segv/.hg/cache
130
130
131 $ $PYTHON <<EOF
131 $ $PYTHON <<EOF
132 > data = open("limit/.hg/store/00changelog.i", "rb").read()
132 > data = open("limit/.hg/store/00changelog.i", "rb").read()
133 > for n, p in [('limit', '\0\0\0\x02'), ('segv', '\0\x01\0\0')]:
133 > for n, p in [('limit', '\0\0\0\x02'), ('segv', '\0\x01\0\0')]:
134 > # corrupt p1 at rev0 and p2 at rev1
134 > # corrupt p1 at rev0 and p2 at rev1
135 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
135 > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
136 > open(n + "/.hg/store/00changelog.i", "wb").write(d)
136 > open(n + "/.hg/store/00changelog.i", "wb").write(d)
137 > EOF
137 > EOF
138
138
139 $ hg debugindex -f1 limit/.hg/store/00changelog.i
139 $ hg debugindex -f1 limit/.hg/store/00changelog.i
140 rev flag offset length size base link p1 p2 nodeid
140 rev flag offset length size base link p1 p2 nodeid
141 0 0000 0 63 62 0 0 2 -1 7c31755bf9b5
141 0 0000 0 63 62 0 0 2 -1 7c31755bf9b5
142 1 0000 63 66 65 1 1 0 2 26333235a41c
142 1 0000 63 66 65 1 1 0 2 26333235a41c
143 $ hg debugindex -f1 segv/.hg/store/00changelog.i
143 $ hg debugindex -f1 segv/.hg/store/00changelog.i
144 rev flag offset length size base link p1 p2 nodeid
144 rev flag offset length size base link p1 p2 nodeid
145 0 0000 0 63 62 0 0 65536 -1 7c31755bf9b5
145 0 0000 0 63 62 0 0 65536 -1 7c31755bf9b5
146 1 0000 63 66 65 1 1 0 65536 26333235a41c
146 1 0000 63 66 65 1 1 0 65536 26333235a41c
147
147
148 $ cat <<EOF > test.py
148 $ cat <<EOF > test.py
149 > import sys
149 > import sys
150 > from mercurial import changelog, vfs
150 > from mercurial import changelog, vfs
151 > cl = changelog.changelog(vfs.vfs(sys.argv[1]))
151 > cl = changelog.changelog(vfs.vfs(sys.argv[1]))
152 > n0, n1 = cl.node(0), cl.node(1)
152 > n0, n1 = cl.node(0), cl.node(1)
153 > ops = [
153 > ops = [
154 > ('reachableroots',
154 > ('reachableroots',
155 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
155 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
156 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
156 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
157 > ('index_headrevs', lambda: cl.headrevs()),
157 > ('index_headrevs', lambda: cl.headrevs()),
158 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
158 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
159 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
159 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
160 > ]
160 > ]
161 > for l, f in ops:
161 > for l, f in ops:
162 > print l + ':',
162 > print l + ':',
163 > try:
163 > try:
164 > f()
164 > f()
165 > print 'uncaught buffer overflow?'
165 > print 'uncaught buffer overflow?'
166 > except ValueError, inst:
166 > except ValueError, inst:
167 > print inst
167 > print inst
168 > EOF
168 > EOF
169
169
170 $ $PYTHON test.py limit/.hg/store
170 $ $PYTHON test.py limit/.hg/store
171 reachableroots: parent out of range
171 reachableroots: parent out of range
172 compute_phases_map_sets: parent out of range
172 compute_phases_map_sets: parent out of range
173 index_headrevs: parent out of range
173 index_headrevs: parent out of range
174 find_gca_candidates: parent out of range
174 find_gca_candidates: parent out of range
175 find_deepest: parent out of range
175 find_deepest: parent out of range
176 $ $PYTHON test.py segv/.hg/store
176 $ $PYTHON test.py segv/.hg/store
177 reachableroots: parent out of range
177 reachableroots: parent out of range
178 compute_phases_map_sets: parent out of range
178 compute_phases_map_sets: parent out of range
179 index_headrevs: parent out of range
179 index_headrevs: parent out of range
180 find_gca_candidates: parent out of range
180 find_gca_candidates: parent out of range
181 find_deepest: parent out of range
181 find_deepest: parent out of range
182
182
183 $ cd ..
183 $ cd ..
184
184
185 #endif
185 #endif
General Comments 0
You need to be logged in to leave comments. Login now