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