Show More
@@ -1,222 +1,222 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 __future__ import print_function |
|
29 | > from __future__ import print_function | |
30 | > from mercurial import changelog, node, vfs |
|
30 | > from mercurial import changelog, node, vfs | |
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 __enter__(self): |
|
44 | > def __enter__(self): | |
45 | > self.real.__enter__() |
|
45 | > self.real.__enter__() | |
46 | > return self |
|
46 | > return self | |
47 | > |
|
47 | > | |
48 | > def __exit__(self, *args, **kwargs): |
|
48 | > def __exit__(self, *args, **kwargs): | |
49 | > return self.real.__exit__(*args, **kwargs) |
|
49 | > return self.real.__exit__(*args, **kwargs) | |
50 | > |
|
50 | > | |
51 | > def opener(*args): |
|
51 | > def opener(*args): | |
52 | > o = vfs.vfs(*args) |
|
52 | > o = vfs.vfs(*args) | |
53 | > def wrapper(*a, **kwargs): |
|
53 | > def wrapper(*a, **kwargs): | |
54 | > f = o(*a, **kwargs) |
|
54 | > f = o(*a, **kwargs) | |
55 | > return singlebyteread(f) |
|
55 | > return singlebyteread(f) | |
56 | > return wrapper |
|
56 | > return wrapper | |
57 | > |
|
57 | > | |
58 | > cl = changelog.changelog(opener('.hg/store')) |
|
58 | > cl = changelog.changelog(opener('.hg/store')) | |
59 | > print(len(cl), 'revisions:') |
|
59 | > print(len(cl), 'revisions:') | |
60 | > for r in cl: |
|
60 | > for r in cl: | |
61 | > print(node.short(cl.node(r))) |
|
61 | > print(node.short(cl.node(r))) | |
62 | > EOF |
|
62 | > EOF | |
63 | $ "$PYTHON" test.py |
|
63 | $ "$PYTHON" test.py | |
64 | 2 revisions: |
|
64 | 2 revisions: | |
65 | 7c31755bf9b5 |
|
65 | 7c31755bf9b5 | |
66 | 26333235a41c |
|
66 | 26333235a41c | |
67 |
|
67 | |||
68 | $ cd .. |
|
68 | $ cd .. | |
69 |
|
69 | |||
70 | #if no-pure |
|
70 | #if no-pure | |
71 |
|
71 | |||
72 | Test SEGV caused by bad revision passed to reachableroots() (issue4775): |
|
72 | Test SEGV caused by bad revision passed to reachableroots() (issue4775): | |
73 |
|
73 | |||
74 | $ cd a |
|
74 | $ cd a | |
75 |
|
75 | |||
76 | $ "$PYTHON" <<EOF |
|
76 | $ "$PYTHON" <<EOF | |
77 | > from __future__ import print_function |
|
77 | > from __future__ import print_function | |
78 | > from mercurial import changelog, vfs |
|
78 | > from mercurial import changelog, vfs | |
79 | > cl = changelog.changelog(vfs.vfs('.hg/store')) |
|
79 | > cl = changelog.changelog(vfs.vfs('.hg/store')) | |
80 | > print('good heads:') |
|
80 | > print('good heads:') | |
81 | > for head in [0, len(cl) - 1, -1]: |
|
81 | > for head in [0, len(cl) - 1, -1]: | |
82 | > print('%s: %r' % (head, cl.reachableroots(0, [head], [0]))) |
|
82 | > print('%s: %r' % (head, cl.reachableroots(0, [head], [0]))) | |
83 | > print('bad heads:') |
|
83 | > print('bad heads:') | |
84 | > for head in [len(cl), 10000, -2, -10000, None]: |
|
84 | > for head in [len(cl), 10000, -2, -10000, None]: | |
85 | > print('%s:' % head, end=' ') |
|
85 | > print('%s:' % head, end=' ') | |
86 | > try: |
|
86 | > try: | |
87 | > cl.reachableroots(0, [head], [0]) |
|
87 | > cl.reachableroots(0, [head], [0]) | |
88 | > print('uncaught buffer overflow?') |
|
88 | > print('uncaught buffer overflow?') | |
89 | > except (IndexError, TypeError) as inst: |
|
89 | > except (IndexError, TypeError) as inst: | |
90 | > print(inst) |
|
90 | > print(inst) | |
91 | > print('good roots:') |
|
91 | > print('good roots:') | |
92 | > for root in [0, len(cl) - 1, -1]: |
|
92 | > for root in [0, len(cl) - 1, -1]: | |
93 | > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))) |
|
93 | > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))) | |
94 | > print('out-of-range roots are ignored:') |
|
94 | > print('out-of-range roots are ignored:') | |
95 | > for root in [len(cl), 10000, -2, -10000]: |
|
95 | > for root in [len(cl), 10000, -2, -10000]: | |
96 | > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))) |
|
96 | > print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))) | |
97 | > print('bad roots:') |
|
97 | > print('bad roots:') | |
98 | > for root in [None]: |
|
98 | > for root in [None]: | |
99 | > print('%s:' % root, end=' ') |
|
99 | > print('%s:' % root, end=' ') | |
100 | > try: |
|
100 | > try: | |
101 | > cl.reachableroots(root, [len(cl) - 1], [root]) |
|
101 | > cl.reachableroots(root, [len(cl) - 1], [root]) | |
102 | > print('uncaught error?') |
|
102 | > print('uncaught error?') | |
103 | > except TypeError as inst: |
|
103 | > except TypeError as inst: | |
104 | > print(inst) |
|
104 | > print(inst) | |
105 | > EOF |
|
105 | > EOF | |
106 | good heads: |
|
106 | good heads: | |
107 | 0: [0] |
|
107 | 0: [0] | |
108 | 1: [0] |
|
108 | 1: [0] | |
109 | -1: [] |
|
109 | -1: [] | |
110 | bad heads: |
|
110 | bad heads: | |
111 | 2: head out of range |
|
111 | 2: head out of range | |
112 | 10000: head out of range |
|
112 | 10000: head out of range | |
113 | -2: head out of range |
|
113 | -2: head out of range | |
114 | -10000: head out of range |
|
114 | -10000: head out of range | |
115 | None: an integer is required |
|
115 | None: an integer is required | |
116 | good roots: |
|
116 | good roots: | |
117 | 0: [0] |
|
117 | 0: [0] | |
118 | 1: [1] |
|
118 | 1: [1] | |
119 | -1: [-1] |
|
119 | -1: [-1] | |
120 | out-of-range roots are ignored: |
|
120 | out-of-range roots are ignored: | |
121 | 2: [] |
|
121 | 2: [] | |
122 | 10000: [] |
|
122 | 10000: [] | |
123 | -2: [] |
|
123 | -2: [] | |
124 | -10000: [] |
|
124 | -10000: [] | |
125 | bad roots: |
|
125 | bad roots: | |
126 | None: an integer is required |
|
126 | None: an integer is required | |
127 |
|
127 | |||
128 | $ cd .. |
|
128 | $ cd .. | |
129 |
|
129 | |||
130 | Test corrupted p1/p2 fields that could cause SEGV at parsers.c: |
|
130 | Test corrupted p1/p2 fields that could cause SEGV at parsers.c: | |
131 |
|
131 | |||
132 | $ mkdir invalidparent |
|
132 | $ mkdir invalidparent | |
133 | $ cd invalidparent |
|
133 | $ cd invalidparent | |
134 |
|
134 | |||
135 | $ hg clone --pull -q --config phases.publish=False ../a limit |
|
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 |
|
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 |
|
137 | $ hg clone --pull -q --config phases.publish=False ../a segv --config format.sparse-revlog=no | |
138 | $ rm -R limit/.hg/cache neglimit/.hg/cache segv/.hg/cache |
|
138 | $ rm -R limit/.hg/cache neglimit/.hg/cache segv/.hg/cache | |
139 |
|
139 | |||
140 | $ "$PYTHON" <<EOF |
|
140 | $ "$PYTHON" <<EOF | |
141 | > data = open("limit/.hg/store/00changelog.i", "rb").read() |
|
141 | > data = open("limit/.hg/store/00changelog.i", "rb").read() | |
142 | > poisons = [ |
|
142 | > poisons = [ | |
143 | > (b'limit', b'\0\0\0\x02'), |
|
143 | > (b'limit', b'\0\0\0\x02'), | |
144 | > (b'neglimit', b'\xff\xff\xff\xfe'), |
|
144 | > (b'neglimit', b'\xff\xff\xff\xfe'), | |
145 | > (b'segv', b'\0\x01\0\0'), |
|
145 | > (b'segv', b'\0\x01\0\0'), | |
146 | > ] |
|
146 | > ] | |
147 | > for n, p in poisons: |
|
147 | > for n, p in poisons: | |
148 | > # corrupt p1 at rev0 and p2 at rev1 |
|
148 | > # corrupt p1 at rev0 and p2 at rev1 | |
149 | > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:] |
|
149 | > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:] | |
150 | > open(n + b"/.hg/store/00changelog.i", "wb").write(d) |
|
150 | > open(n + b"/.hg/store/00changelog.i", "wb").write(d) | |
151 | > EOF |
|
151 | > EOF | |
152 |
|
152 | |||
153 | $ hg -R limit debugrevlogindex -f1 -c |
|
153 | $ hg -R limit debugrevlogindex -f1 -c | |
154 | rev flag size link p1 p2 nodeid |
|
154 | rev flag size link p1 p2 nodeid | |
155 | 0 0000 62 0 2 -1 7c31755bf9b5 |
|
155 | 0 0000 62 0 2 -1 7c31755bf9b5 | |
156 | 1 0000 65 1 0 2 26333235a41c |
|
156 | 1 0000 65 1 0 2 26333235a41c | |
157 |
|
157 | |||
158 | $ hg -R limit debugdeltachain -c |
|
158 | $ hg -R limit debugdeltachain -c | |
159 | rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio |
|
159 | rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio | |
160 | 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000 |
|
160 | 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000 | |
161 | 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000 |
|
161 | 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000 | |
162 |
|
162 | |||
163 | $ hg -R neglimit debugrevlogindex -f1 -c |
|
163 | $ hg -R neglimit debugrevlogindex -f1 -c | |
164 | rev flag size link p1 p2 nodeid |
|
164 | rev flag size link p1 p2 nodeid | |
165 | 0 0000 62 0 -2 -1 7c31755bf9b5 |
|
165 | 0 0000 62 0 -2 -1 7c31755bf9b5 | |
166 | 1 0000 65 1 0 -2 26333235a41c |
|
166 | 1 0000 65 1 0 -2 26333235a41c | |
167 |
|
167 | |||
168 | $ hg -R segv debugrevlogindex -f1 -c |
|
168 | $ hg -R segv debugrevlogindex -f1 -c | |
169 | rev flag size link p1 p2 nodeid |
|
169 | rev flag size link p1 p2 nodeid | |
170 | 0 0000 62 0 65536 -1 7c31755bf9b5 |
|
170 | 0 0000 62 0 65536 -1 7c31755bf9b5 | |
171 | 1 0000 65 1 0 65536 26333235a41c |
|
171 | 1 0000 65 1 0 65536 26333235a41c | |
172 |
|
172 | |||
173 | $ hg -R segv debugdeltachain -c |
|
173 | $ hg -R segv debugdeltachain -c | |
174 | rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio |
|
174 | rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio | |
175 | 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000 |
|
175 | 0 1 1 -1 base 63 62 63 1.01613 63 0 0.00000 | |
176 | 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000 |
|
176 | 1 2 1 -1 base 66 65 66 1.01538 66 0 0.00000 | |
177 |
|
177 | |||
178 | $ cat <<EOF > test.py |
|
178 | $ cat <<EOF > test.py | |
179 | > from __future__ import print_function |
|
179 | > from __future__ import print_function | |
180 | > import sys |
|
180 | > import sys | |
181 | > from mercurial import changelog, vfs |
|
181 | > from mercurial import changelog, vfs | |
182 | > cl = changelog.changelog(vfs.vfs(sys.argv[1])) |
|
182 | > cl = changelog.changelog(vfs.vfs(sys.argv[1])) | |
183 | > n0, n1 = cl.node(0), cl.node(1) |
|
183 | > n0, n1 = cl.node(0), cl.node(1) | |
184 | > ops = [ |
|
184 | > ops = [ | |
185 | > ('reachableroots', |
|
185 | > ('reachableroots', | |
186 | > lambda: cl.index.reachableroots2(0, [1], [0], False)), |
|
186 | > lambda: cl.index.reachableroots2(0, [1], [0], False)), | |
187 | > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])), |
|
187 | > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])), | |
188 | > ('index_headrevs', lambda: cl.headrevs()), |
|
188 | > ('index_headrevs', lambda: cl.headrevs()), | |
189 | > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)), |
|
189 | > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)), | |
190 | > ('find_deepest', lambda: cl.ancestor(n0, n1)), |
|
190 | > ('find_deepest', lambda: cl.ancestor(n0, n1)), | |
191 | > ] |
|
191 | > ] | |
192 | > for l, f in ops: |
|
192 | > for l, f in ops: | |
193 | > print(l + ':', end=' ') |
|
193 | > print(l + ':', end=' ') | |
194 | > try: |
|
194 | > try: | |
195 | > f() |
|
195 | > f() | |
196 | > print('uncaught buffer overflow?') |
|
196 | > print('uncaught buffer overflow?') | |
197 | > except ValueError as inst: |
|
197 | > except ValueError as inst: | |
198 | > print(inst) |
|
198 | > print(inst) | |
199 | > EOF |
|
199 | > EOF | |
200 |
|
200 | |||
201 | $ "$PYTHON" test.py limit/.hg/store |
|
201 | $ "$PYTHON" test.py limit/.hg/store | |
202 | reachableroots: parent out of range |
|
202 | reachableroots: parent out of range | |
203 | compute_phases_map_sets: parent out of range |
|
203 | compute_phases_map_sets: parent out of range | |
204 | index_headrevs: parent out of range |
|
204 | index_headrevs: parent out of range | |
205 | find_gca_candidates: parent out of range |
|
205 | find_gca_candidates: parent out of range | |
206 | find_deepest: parent out of range |
|
206 | find_deepest: parent out of range | |
207 | $ "$PYTHON" test.py neglimit/.hg/store |
|
207 | $ "$PYTHON" test.py neglimit/.hg/store | |
208 | reachableroots: parent out of range |
|
208 | reachableroots: parent out of range | |
209 | compute_phases_map_sets: parent out of range |
|
209 | compute_phases_map_sets: parent out of range | |
210 | index_headrevs: parent out of range |
|
210 | index_headrevs: parent out of range | |
211 | find_gca_candidates: parent out of range |
|
211 | find_gca_candidates: parent out of range | |
212 | find_deepest: parent out of range |
|
212 | find_deepest: parent out of range | |
213 | $ "$PYTHON" test.py segv/.hg/store |
|
213 | $ "$PYTHON" test.py segv/.hg/store | |
214 | reachableroots: parent out of range |
|
214 | reachableroots: parent out of range | |
215 | compute_phases_map_sets: parent out of range |
|
215 | compute_phases_map_sets: parent out of range | |
216 | index_headrevs: parent out of range |
|
216 | index_headrevs: parent out of range | |
217 | find_gca_candidates: parent out of range |
|
217 | find_gca_candidates: parent out of range | |
218 | find_deepest: parent out of range |
|
218 | find_deepest: parent out of range | |
219 |
|
219 | |||
220 | $ cd .. |
|
220 | $ cd .. | |
221 |
|
221 | |||
222 | #endif |
|
222 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now